1、建立用户和用户受权mysql
MySQL5.7建立用户和用户受权命令能够同时执行sql
grant all privileges on *.* to 'Gary'@'%' identified by 'Gary@2019'
MySQL8.0建立用户和用户受权的命令须要分开执行数据库
建立用户ide
create user 'Gary'@'%' identified by 'Gary@2019';
用户受权【给予全部权限】测试
grant all privileges on *.* to 'Gary'@'%'
2、认证插件更新ui
MySQL8.0中默认的身份插件是caching_sha2_password,替代了以前mysql_native_passwordspa
经过查看default_authentication_plugin和mysql.user能够查看系统中的变化插件
show variables like 'default_authentication%'
select user,host,plugin from mysql.user;
也能够把8.0中身份认证插件caching_sha2_password改回原来的mysql_native_passwordcode
alter user 'Gary'@'%' identified with mysql_native_password by 'Gary@2020'
3、密码管理blog
MySQL8.0开始容许限制重复使用之前的密码
使用 show variables like 'password%' 指令可查看对密码管理的限制
password_history = 3 #新密码不能和近期3次内旧密码相同 password_reuse_interval = 90 #新密码不能喝近90天密码相同 password_require_current = ON #修改密码时用户须要提供当前密码
动态修改其中的参数
alter user 'Gary'@'%' password history 5;
可同过修改用户密码语句进行测试
alter user 'Gary'@'%' identified by 'Gary@2019';
可查看用户修改密码历史表
select * from mysql.password_history;
当设置password_require_current = ON,用户修改密码时须要提供当前密码
alter user user() identified by 'Gary@2021' replace 'Gary@2020';
4、角色管理
MySQL8.0提供了角色管理的新功能,角色是一组权限的集合
角色也是一个用户,用角色去模拟用户,能够对角色去进行权限受权
【实践】
建立数据库
create database garydb;
建立数据库表
create table garydb.tl(id int)
建立一个角色【新建立出来的角色无任何权限】
create role 'Gary_role';
给角色授予增、删、改的权限
grant insert,update,delete on garydb.* to 'Gary_role';
建立一个用户
create user 'user1' identified by 'User1@2019';
将角色授予给用户
grant 'Gary_role' to 'user1';
显示用户权限
show grants for 'user1';
show grants for 'user1' using 'Gary_role';