角色管理
角色管理
MySQL8新增的功能
– 創建角色 role
create role ‘dev_read’,‘dev_write’
– 給角色分配權限
grant select on mydb.* to ‘dev_read’
grant insert,update,delete on mydb.* to ‘dev_write’
– 創建用戶
create user ‘user1’@‘localhost’ identified by ‘user1’;
create user ‘user2’@‘localhost’ identified by ‘user2’;
create user ‘user3’@‘localhost’ identified by ‘user3’;
– 給用戶分配角色
grant ‘dev_read’ to ‘user1’@‘localhost’;
grant ‘dev_write’ to ‘user2’@‘localhost’;
grant ‘dev_write’ to ‘user3’@‘localhost’ with admin option ;
– 激活角色 !!!
set default role all to ‘user1’@‘localhost’,‘user2’@‘localhost’,‘user3’@‘localhost’
– 給用戶撤銷角色
revoke ‘dev_read’ from ‘user1’@‘localhost’;
revoke ‘dev_write’ from ‘user2’@‘localhost’;
revoke ‘dev_write’ from ‘user3’@‘localhost’;
– 刪除角色
drop role ‘dev_read’,‘dev_write’
– 刪除用戶
drop user ‘user1’@‘localhost’,‘user2’@‘localhost’,‘user3’@‘localhost’
總結
- 上一篇: 断言、触发器、存储过程
- 下一篇: 外星人笔记本电脑标配240W电源拆解外星