| 1 |
create user user_a@localhost; |
| 2 |
create user user_b@localhost; |
| 3 |
create role role_a; |
| 4 |
create role role_b; |
| 5 |
grant role_a to user_a@localhost; |
| 6 |
grant role_b to user_b@localhost; |
| 7 |
grant role_a to user_a@localhost; |
| 8 |
grant select on *.* to role_a; |
| 9 |
grant role_b to user_b@localhost; |
| 10 |
grant insert, update on *.* to role_b; |
| 11 |
set default role role_a for user_b@localhost; |
| 12 |
ERROR 42000: Access denied for user 'user_a'@'localhost' to database 'mysql' |
| 13 |
set default role role_a for user_a@localhost; |
| 14 |
set default role invalid_role for user_a@localhost; |
| 15 |
ERROR OP000: Invalid role specification `invalid_role` |
| 16 |
set default role role_b for user_a@localhost; |
| 17 |
ERROR OP000: User `user_a`@`localhost` has not been granted role `role_b` |
| 18 |
set default role role_b for user_b@localhost; |
| 19 |
show grants; |
| 20 |
Grants for user_a@localhost |
| 21 |
GRANT `role_a` TO `user_a`@`localhost` |
| 22 |
GRANT USAGE ON *.* TO `user_a`@`localhost` |
| 23 |
GRANT SELECT ON *.* TO `role_a` |
| 24 |
SET DEFAULT ROLE `role_a` FOR `user_a`@`localhost` |
| 25 |
select user, host, default_role from mysql.user where user like 'user_%'; |
| 26 |
User Host default_role |
| 27 |
user_a localhost role_a |
| 28 |
user_b localhost role_b |
| 29 |
set default role NONE for current_user; |
| 30 |
select user, host, default_role from mysql.user where user like 'user_%'; |
| 31 |
User Host default_role |
| 32 |
user_a localhost |
| 33 |
user_b localhost role_b |
| 34 |
set default role current_role for current_user; |
| 35 |
select user, host, default_role from mysql.user where user like 'user_%'; |
| 36 |
User Host default_role |
| 37 |
user_a localhost role_a |
| 38 |
user_b localhost role_b |
| 39 |
set default role role_b for current_user; |
| 40 |
ERROR OP000: User `user_a`@`localhost` has not been granted role `role_b` |
| 41 |
show grants; |
| 42 |
Grants for user_b@localhost |
| 43 |
GRANT `role_b` TO `user_b`@`localhost` |
| 44 |
GRANT USAGE ON *.* TO `user_b`@`localhost` |
| 45 |
GRANT INSERT, UPDATE ON *.* TO `role_b` |
| 46 |
SET DEFAULT ROLE `role_b` FOR `user_b`@`localhost` |
| 47 |
select user, host, default_role from mysql.user where user like 'user_%'; |
| 48 |
ERROR 42000: SELECT command denied to user 'user_b'@'localhost' for table `mysql`.`user` |
| 49 |
set default role NONE for user_a@localhost; |
| 50 |
show grants; |
| 51 |
Grants for user_a@localhost |
| 52 |
GRANT `role_a` TO `user_a`@`localhost` |
| 53 |
GRANT USAGE ON *.* TO `user_a`@`localhost` |
| 54 |
GRANT INSERT, UPDATE ON *.* TO `role_b` |
| 55 |
select user, host, default_role from mysql.user where user like 'user_%'; |
| 56 |
ERROR 42000: SELECT command denied to user 'user_a'@'localhost' for table `mysql`.`user` |
| 57 |
drop role role_a; |
| 58 |
drop role role_b; |
| 59 |
drop user user_a@localhost; |
| 60 |
drop user user_b@localhost; |