一:创建角色
# 语法:
CREATE ROLE [IF NOT EXISTS] role [, role ] ...
# 创建两个角色r1,r2
mysql> create role 'r1','r2';
Query OK, 0 rows affected (0.00 sec)
mysql>
## 查看已经创建的角色
## 角色也存放在user表中,其实,角色很用户只是逻辑上做了区分,给我感觉,角色就是一个没有密码的用户
## 我们看默认创建角色是的host是%,当然,创建角色也可以指定IP或localhost
mysql> select host,user,authentication_string from mysql.user where user in ('r1','r2');
+------+------+-----------------------+
| host | user | authentication_string |
+------+------+-----------------------+
| % | r1 | |
| % | r2 | |
+------+------+-----------------------+
2 rows in set (0.00 sec)
mysql>
二:给角色授权
mysql> grant select,insert,update,delete,create,drop on am.* to 'r1';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select,insert,update,delete on am.* to 'r2' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql>