| 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_role1; |
| 6 |
select user, host from mysql.user where user not like 'root'; |
| 7 |
User Host |
| 8 |
mariadb.sys localhost |
| 9 |
test_role1 |
| 10 |
test_role2 |
| 11 |
test_user localhost |
| 12 |
select * from mysql.roles_mapping; |
| 13 |
Host User Role Admin_option |
| 14 |
test_role1 test_role2 N |
| 15 |
localhost root test_role1 Y |
| 16 |
localhost root test_role2 Y |
| 17 |
localhost test_user test_role1 N |
| 18 |
grant select on mysql.roles_mapping to test_role2; |
| 19 |
select * from mysql.roles_mapping; |
| 20 |
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping` |
| 21 |
show grants; |
| 22 |
Grants for test_user@localhost |
| 23 |
GRANT USAGE ON *.* TO `test_user`@`localhost` |
| 24 |
GRANT `test_role1` TO `test_user`@`localhost` |
| 25 |
select current_user(), current_role(); |
| 26 |
current_user() current_role() |
| 27 |
test_user@localhost NULL |
| 28 |
set role test_role1; |
| 29 |
select current_user(), current_role(); |
| 30 |
current_user() current_role() |
| 31 |
test_user@localhost test_role1 |
| 32 |
show grants; |
| 33 |
Grants for test_user@localhost |
| 34 |
GRANT SELECT ON `mysql`.`roles_mapping` TO `test_role2` |
| 35 |
GRANT USAGE ON *.* TO `test_role1` |
| 36 |
GRANT USAGE ON *.* TO `test_role2` |
| 37 |
GRANT USAGE ON *.* TO `test_user`@`localhost` |
| 38 |
GRANT `test_role1` TO `test_user`@`localhost` |
| 39 |
GRANT `test_role2` TO `test_role1` |
| 40 |
select * from mysql.roles_mapping; |
| 41 |
Host User Role Admin_option |
| 42 |
test_role1 test_role2 N |
| 43 |
localhost root test_role1 Y |
| 44 |
localhost root test_role2 Y |
| 45 |
localhost test_user test_role1 N |
| 46 |
show grants; |
| 47 |
Grants for test_user@localhost |
| 48 |
GRANT SELECT ON `mysql`.`roles_mapping` TO `test_role2` |
| 49 |
GRANT USAGE ON *.* TO `test_role1` |
| 50 |
GRANT USAGE ON *.* TO `test_role2` |
| 51 |
GRANT USAGE ON *.* TO `test_user`@`localhost` |
| 52 |
GRANT `test_role1` TO `test_user`@`localhost` |
| 53 |
GRANT `test_role2` TO `test_role1` |
| 54 |
use mysql; |
| 55 |
set role none; |
| 56 |
select current_user(), current_role(); |
| 57 |
current_user() current_role() |
| 58 |
test_user@localhost NULL |
| 59 |
select * from mysql.roles_mapping; |
| 60 |
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping` |
| 61 |
drop user 'test_user'@'localhost'; |
| 62 |
select * from mysql.tables_priv; |
| 63 |
Host Db User Table_name Grantor Timestamp Table_priv Column_priv |
| 64 |
localhost mysql mariadb.sys global_priv root@localhost 0000-00-00 00:00:00 Select,Delete |
| 65 |
mysql test_role2 roles_mapping root@localhost 0000-00-00 00:00:00 Select |
| 66 |
revoke select on mysql.roles_mapping from test_role2; |
| 67 |
delete from mysql.user where user like'test_%'; |
| 68 |
delete from mysql.roles_mapping where Role like 'test%'; |
| 69 |
flush privileges; |