MySQL資料庫使用者許可權操作

2021-10-03 10:14:14 字數 2275 閱讀 5913

一、建立使用者與資料操作許可權的分配;

1.1、指定使用者名稱,登入ip(如果不限制ip則改為%),密碼

create user 'user_name'@'***.***.***.***' identified by 'pwd';
1.2、為已建立的使用者開放新的登入ip(假如該使用者已有增、刪、改、查、建立表的許可權)

grant select,insert,update,delete on *.* to "user_name"@'xx.x.xx.***' identified by 'pwd' with grant option;
1.3、為已建立使用者增加 a 資料庫下 b 表的查詢許可權(一次增加一種許可權);

grant select on a . b to 'user_name'@'xx.x.xx.***';

grant select(id, name, age) on a . b to 'user_name'@'xx.x.xx.***';(針對指定的列操作許可權)

同理增、刪、改、查、建立表、的許可權方法同上,將select換成對應的insert、delete、update、select即可

a 資料庫改為 * 則對應所有資料庫

b 表改為 * 則對應所有資料表

1.4、也可以一次增加多種許可權;

grant select, insert, update, delete on * . * to user_name@'%';
二、給使用者開放建立和修改表結構的許可權;

2.1、給使用者開放建立表的許可權;

grant create on * . * to user_name@'%';
2.2、給使用者開放修改表結構的許可權;

grant alter on * . * to user_name@'%';
3.3、給使用者開放刪除表的許可權;

grant drop on * . * to user_name@'%';
三、建立外來鍵許可權;

grant references on * . * to user_name@'%';
四、建立索引許可權;

grant index on * . * to user_name@'%';
五、操作臨時表許可權;

grant create temporary tables on * . * to user_name@'%';
六、操作檢視,檢視檢視sql許可權;

grant create,show view on * . * to user_name@'%';
七、操作函式的許可權;

7.1、建立函式、儲存過程的許可權;

grant create routine on * . * to user_name@'%';
7.2、刪除和更新函式的許可權;

grant alter routine on * . * to user_name@'%';
7.3、執行函式、儲存過程的許可權;

grant execute on * . * to user_name@'%';
八、檢視使用者許可權;

1、當前使用者許可權;

show grants;
2、其他使用者的許可權;

show grants for user_name@'%';
九、撤銷使用者的許可權。

在賦予許可權的語句中將grant換成roveke,to換成from即可

revoke all on *.* from user_name@'%';(all代表所有許可權)
十、mysql grant、revoke 使用者許可權注意事項

1. grant, revoke 使用者許可權後,該使用者只有重新連線 mysql 資料庫,許可權才能生效。

2. 如果想讓授權的使用者,也可以將這些許可權 grant 給其他使用者,需要選項 「grant option「

grant select on testdb.* to user_name@'%' with grant option;

這個特性一般用不到。實際中,資料庫許可權最好由 dba 來統一管理。

mysql資料庫使用者許可權管理

知識點總結 三句話 1.create user golden localhost identified by gd2017 2.grant all on test.to golden localhost 3.flush privileges 解釋 1 create user 語句用於建立使用者 及密...

Mysql資料庫學習 使用者及許可權操作

1.使用者操作 1.1新建普通使用者 1.2刪除普通使用者 1.3修改使用者密碼 2.許可權操作 2.1使用者授權 2.2使用者收回許可權 2.3使用者許可權檢視 3.角色操作 3.1建立角色 3.2角色授權 3.3為使用者賦予角色 4.訪問控制 create user 使用者名稱 localhos...

mysql資料庫新增使用者與使用者許可權

mysql資料庫新增使用者及分配許可權的方法。1,建立使用者並分配許可權 insert into mysql.user host,user,password values localhost phplamp password 1234 建立使用者 grant all privileges on db...