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';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章