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';