mysql 帳戶管理 MySQL常用使用者管理命令

2021-10-17 17:41:42 字數 2670 閱讀 4173

文章目錄

[隱藏]

1、新增使用者

2、刪除使用者

3、許可權**

4、建立使用者授權一起實現

5、限制使用者資源

6、使用者密碼設定

7、關於加密

8、授權精確到列

1、新增使用者

本機訪問許可權:

mysql> grant all privileges on *.* to 『username』@』localhost』 identified by 『password』 with grant option;

遠端訪問許可權:

mysql> grant all privileges on *.* to 『username』@』%』 identified by 『password』 with grant option;

另外還有一種方法是直接insert into user,注意這種方法之後需要 flush privileges 讓伺服器重讀授權表。

insert into user(host,user,password,ssl_cipher,x509_issuer,x509_subject) values(『localhost』,』xff』,password(『xff』),」,」,」);

flush privileges;

note:1)必須要加上ssl_cipher,x509_issuer,x509_subject三列,以為其預設值不為空(資料庫版本為:5.0.51b)

2)flush privileges過載授權表,使許可權更改生效

3)mysql是通過user表,db表,host表,tables_priv 表,columns_priv 表這5張表實現使用者許可權控制,均可以通過直接對這些表的操作以達到對使用者的管理

2、刪除使用者

drop user admin@localhost;(@不加預設為「%」)

3、許可權**

revoke delete on test.* from admin@』localhost』;

4、建立使用者授權一起實現

grant select,insert,update,delete on *.* to 『admin2′@』%』 identified by 『admin2′ with grant option;

note:在mysql中,如果@後面的登入範圍不同,帳號可以一樣

5、限制使用者資源

mysql> grant all on customer.* to 『francis』@』localhost』

-> identified by 『frank』

-> with max_queries_per_hour 20

-> max_updates_per_hour 10

-> max_connections_per_hour 5

-> max_user_connections 2;

6、使用者密碼設定

使用mysqladmin:

shell> mysqladmin -u user_name -h host_name password "newpwd"

或在mysql裡執行語句:

mysql> set password for 『username』@』%』 = password(『password』);

如果只是更改自己的密碼,則:

mysql> set password = password(『password』);

在全域性級別使用grant usage語句(在*.*)來指定某個賬戶的密碼:

mysql> grant usage on *.* to 『username』@』%』 identified by 『password』;

或直接修改mysql庫表:

mysql> update user set password = password(『bagel』)  where host = 『%』 and user = 『francis』;

mysql> flush privileges;

修改root密碼:

update mysql.user set password=password(『passw0rd』) where user=』root』;

flush privileges;

7、關於加密

mysql> select password(『password』);

| password(『password』)                      |

| *2470c0c06dee42fd1618bb99005adca2ec9d1e19 |

1 row in set (0.00 sec)

mysql> select md5(『hello』);

| md5(『hello』)                     |

| 5d41402abc4b2a76b9719d911017c592 |

1 row in set (0.00 sec)

mysql> select sha1(『abc』);

-> 『a9993e364706816aba3e25717850c26c9cd0d89d』

sha1()是為字串算出乙個 sha1 160位元檢查和,如rfc 3174 (安全雜湊演算法)中所述。

8、授權精確到列

grant select (cur_url,pre_url) on test.abc to admin@localhost;

mysql常用使用者管理命令

mysql建立遠端帳戶 mysql 建立遠端帳戶

linux上安裝的mysql。預設狀況下只有乙個帳戶 root 此帳戶只能進行本地鏈結 對外拒絕鏈結 mysql 咱們須要建立乙個容許遠端登陸的資料庫帳戶 這樣才能夠方便的進行遠端操做資料 linux 預設狀況下 linux內的mysql資料庫mysql,user表內的使用者許可權只是對localh...

mysql常問內容 mysql常問問題

前言 一些自己遇到的問題及理解 需補充修改 索引型別 主鍵索引 普通索引 符合索引 唯一索引 全文索引 索引 查詢資料的資料結構,索引占用磁碟空間,更新資料的時候影響更新表的效率 資料儲存型別 聚簇索引 非聚簇索引 聚簇 採用b 樹的資料結構,聚簇索引葉子節點存放證章表的資料,所以主鍵索引就是用的聚...

mysql檢視mylog命令 mysql常用命令

連線mysql 1.登入mysql資料庫 mysql u使用者名稱 p密碼 示例 2.登入遠端主機的mysql mysql h遠端主機ip位址 u使用者名稱 p密碼 示例 注 建立使用者命令格式為 create user hehe 192.168.93.151 3.退出mysql命令 exit 修改...