mysql 常用的命令之使用者篇

2021-09-20 17:16:53 字數 1390 閱讀 8910

新建使用者: 

create user 使用者名稱;                         --建立乙個空密碼使用者.

create user 使用者名稱 identified by '密碼';           --新建使用者時建立密碼.

grant select[,insert...] on mysql.user to 使用者名稱 identified by '密碼';   --新建使用者的同時,授予使用者select mysql資料庫user表的許可權.

更新密碼: 

1. set password=password('密碼');                --修改當前使用者密碼.

2. set password for 使用者名稱=password('密碼');         --修改指定使用者密碼.

3. update mysql.user set password=password('密碼') where user='使用者名稱'  --用update直接修改

flush privilegs;                                     --更新記憶體使之生效

檢視使用者許可權:

use mysql

select * from user where user='test'\g;           --格式化檢視test使用者的許可權.

刪除使用者:

delete from user where user='';   --刪除user表中,使用者名為空的列,必加from。防止任務使用者都可以隨便登入

flush privileges;             --重新整理記憶體使修改生效       

給使用者授權:

grant all on mysql.user to test@'%';     --賦予所有名為test的使用者mysql資料庫user表的所有許可權.

grant all on stu.* to test2@'%';       --賦予所有test2使用者對stu資料庫的許可權

查詢使用者許可權:

select * from mysql.user where user='隨便乙個使用者名稱';   --查詢使用者在資料庫級的許可權

show grants;                              --查詢當前使用者許可權

show grants for 使用者名稱;                       --查詢指定使用者的許可權

迴改許可權:

revoke all privileges on mysql.user from test;       --**test使用者對mysql.user資料表的所有許可權.

revoke select on mysql.user from test2;           --**test2對mysql.user資料表的select許可權.

mysql常用命令之 使用者密碼修改

建立使用者 create user user1 localhost identified by pass1 grant select,insert,update,delete on to user1 localhost grant all on to user1 localhost 1.修改root...

mysql常用命令之 使用者密碼修改

mysql常用命令之 使用者密碼修改 建立使用者 create user user1 localhost identified by pass1 grant select,insert,update,delete on to user1 localhost grant all on to user1...

mysql之使用者授權

授權命令 1.全部許可權 grant all on to user 192.168.10.2 identified by pass 2.部分許可權 grant select,insert into on to user 192.168.10.2 identified by pass 檢視使用者授權表...