# 管理角色

__*TiDB 角色管理*__

+ 赋予角色权限:
  + `grant select on test.* to 'r_dev'@'localhost';`

+ 将角色授予用户:
  + `grant 'r_admin' to 'user1'@'localhost';`


+ 查看角色拥有的权限:
  + `show grants for 'dev1'@'localhost';`

+ 回收角色权限:
  + `revoke insert, update, delete on test.* form 'r_dev'@'localhost';`

+ 删除角色:
  + `drop role 'r_admin', 'r_dev'@'localhost';`

-------------------------------------------------------------
1. 赋予角色权限
为 r_dev 角色授予数据库 test 的读权限:
GRANT SELECT ON test.* TO 'r_dev'@'localhost';

2. 将角色授予用户
将 r_admin 角色授予用户  'user1'@'localhost':
GRANT 'r_admin' TO 'user1'@'localhost';

3. 查看角色拥有的权限
SHOW GRANTS FOR 'dev1'@'localhost';
+-------------------------------------------------+
| Grants for dev1@localhost                       |
+-------------------------------------------------+
| GRANT USAGE ON *.* TO `dev1`@`localhost`        |
| GRANT `app_developer`@`%` TO `dev1`@`localhost` |
+-------------------------------------------------+

4. 回收角色权限
回收 r_dev 角色的 test 数据库下的写权限:
REVOKE INSERT, UPDATE, DELETE ON test.* FROM 'r_dev'@'localhost';

5. 删除角色
DROP ROLE 'r_admin', 'r_dev'@'localhost';

详细操作请参考:https://docs.pingcap.com/zh/tidb/stable/role-based-access-control