MySQL 授權管理

純記錄供參考。

對增量授權

增量授權即當前mysql.user中不存在的用戶

mysql5.6、5.7

5.6、5.7可以一句授權語句進行創建用戶及授權

# 當授權類型爲 replication client, replication slave時
grant permisson on *.* to 'user'@'host' identified by 'password';

# 當授權類型爲select、update、create、drop等時
grant permisson on database.* to 'user'@'host' identified by 'password';

mysql8.0

8.0授權需要先創建用戶,再進行授權

create user if not exists 'user'@'host' identified with mysql_native_password by 'password';

# 當授權類型爲 replication client, replication slave時
grant permisson on *.* to 'user'@'host' identified by 'password';

# 當授權類型爲select、update、create、drop等時
grant permisson on database.* to 'user'@'host' identified by 'password';

對存量授權

存量授權即當前mysql.user中存在的用戶,一般來講,爲了便於管理,多個授權的密碼應該一致,而dbauser往往並不知道普通用戶的密碼

由於5.6的user表中使用的是password字段,而5.7、8.0使用的爲authentication_string,所以針對兩種情況使用不一樣的方法

mysql 5.6

# 先創建一個對應ip的用戶
grant usage on *.* to 'user'@'host';

# 設置已存在的密文密碼
set password for 'user'@'host'='password'

mysql 5.7、8.0

#創建用戶,這裏用的是 AS ,後面的password是密文密碼
create user if not exists 'user'@'host' identified with mysql_native_password as 'password';

此後的授權與增量授權相同

# 當授權類型爲 replication client, replication slave時
grant permisson on *.* to 'user'@'host' identified by 'password';

# 當授權類型爲select、update、create、drop等時
grant permisson on database.* to 'user'@'host' identified by 'password';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章