| 1 |
create user test_user@localhost; |
| 2 |
create role test_role1; |
| 3 |
create role test_role2; |
| 4 |
grant test_role1 to test_user@localhost; |
| 5 |
grant test_role2 to test_user@localhost; |
| 6 |
grant test_role2 to test_role1; |
| 7 |
select user, host from mysql.user where user not like 'root'; |
| 8 |
User Host |
| 9 |
mariadb.sys localhost |
| 10 |
test_role1 |
| 11 |
test_role2 |
| 12 |
test_user localhost |
| 13 |
select * from mysql.roles_mapping; |
| 14 |
Host User Role Admin_option |
| 15 |
test_role1 test_role2 N |
| 16 |
localhost root test_role1 Y |
| 17 |
localhost root test_role2 Y |
| 18 |
localhost test_user test_role1 N |
| 19 |
localhost test_user test_role2 N |
| 20 |
select user, host from mysql.db; |
| 21 |
user host |
| 22 |
grant select on mysql.* to test_role2; |
| 23 |
flush privileges; |
| 24 |
select * from mysql.roles_mapping; |
| 25 |
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping` |
| 26 |
select current_user(), current_role(); |
| 27 |
current_user() current_role() |
| 28 |
test_user@localhost NULL |
| 29 |
set role test_role1; |
| 30 |
select current_user(), current_role(); |
| 31 |
current_user() current_role() |
| 32 |
test_user@localhost test_role1 |
| 33 |
select * from mysql.roles_mapping; |
| 34 |
Host User Role Admin_option |
| 35 |
test_role1 test_role2 N |
| 36 |
localhost root test_role1 Y |
| 37 |
localhost root test_role2 Y |
| 38 |
localhost test_user test_role1 N |
| 39 |
localhost test_user test_role2 N |
| 40 |
set role none; |
| 41 |
select current_user(), current_role(); |
| 42 |
current_user() current_role() |
| 43 |
test_user@localhost NULL |
| 44 |
select * from mysql.roles_mapping; |
| 45 |
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping` |
| 46 |
set role test_role2; |
| 47 |
select current_user(), current_role(); |
| 48 |
current_user() current_role() |
| 49 |
test_user@localhost test_role2 |
| 50 |
select * from mysql.roles_mapping; |
| 51 |
Host User Role Admin_option |
| 52 |
test_role1 test_role2 N |
| 53 |
localhost root test_role1 Y |
| 54 |
localhost root test_role2 Y |
| 55 |
localhost test_user test_role1 N |
| 56 |
localhost test_user test_role2 N |
| 57 |
create role test_role3; |
| 58 |
grant test_role3 to test_role2; |
| 59 |
create role test_role4; |
| 60 |
grant test_role4 to test_role3; |
| 61 |
set role test_role1; |
| 62 |
delete from mysql.user where user='no such user'; |
| 63 |
ERROR 42000: DELETE command denied to user 'test_user'@'localhost' for table `mysql`.`user` |
| 64 |
grant delete on mysql.* to test_role4; |
| 65 |
set role test_role1; |
| 66 |
delete from mysql.user where user='no such user'; |
| 67 |
show grants; |
| 68 |
Grants for test_user@localhost |
| 69 |
GRANT DELETE ON `mysql`.* TO `test_role4` |
| 70 |
GRANT SELECT ON `mysql`.* TO `test_role2` |
| 71 |
GRANT USAGE ON *.* TO `test_role1` |
| 72 |
GRANT USAGE ON *.* TO `test_role2` |
| 73 |
GRANT USAGE ON *.* TO `test_role3` |
| 74 |
GRANT USAGE ON *.* TO `test_role4` |
| 75 |
GRANT USAGE ON *.* TO `test_user`@`localhost` |
| 76 |
GRANT `test_role1` TO `test_user`@`localhost` |
| 77 |
GRANT `test_role2` TO `test_role1` |
| 78 |
GRANT `test_role2` TO `test_user`@`localhost` |
| 79 |
GRANT `test_role3` TO `test_role2` |
| 80 |
GRANT `test_role4` TO `test_role3` |
| 81 |
drop user test_user@localhost; |
| 82 |
drop role test_role1, test_role2, test_role3, test_role4; |