2013-10-18 21:21:10 +02:00
|
|
|
create user test_user@localhost;
|
2013-10-18 15:47:49 +02:00
|
|
|
create role test_role1;
|
|
|
|
create role test_role2;
|
2013-10-18 21:21:10 +02:00
|
|
|
grant test_role1 to test_user@localhost;
|
2013-10-18 21:34:44 +02:00
|
|
|
grant test_role2 to test_role1;
|
2013-10-18 15:47:49 +02:00
|
|
|
select user, host from mysql.user where user not like 'root';
|
|
|
|
user host
|
|
|
|
test_role1
|
|
|
|
test_role2
|
|
|
|
test_user localhost
|
|
|
|
select * from mysql.roles_mapping;
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
2013-10-18 21:27:07 +02:00
|
|
|
localhost root test_role1 Y
|
|
|
|
localhost root test_role2 Y
|
2013-10-18 21:21:10 +02:00
|
|
|
localhost test_user test_role1 N
|
2013-10-18 18:08:42 +02:00
|
|
|
grant select on mysql.roles_mapping to test_role2;
|
2013-10-18 15:47:49 +02:00
|
|
|
select * from mysql.roles_mapping;
|
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table 'roles_mapping'
|
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
|
|
|
GRANT USAGE ON *.* TO 'test_user'@'localhost'
|
|
|
|
GRANT test_role1 TO 'test_user'@'localhost'
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
2013-10-18 18:09:08 +02:00
|
|
|
test_user@localhost NULL
|
2013-10-18 15:47:49 +02:00
|
|
|
set role test_role1;
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
|
|
|
test_user@localhost test_role1
|
2013-10-18 15:47:49 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
|
|
|
GRANT SELECT ON `mysql`.`roles_mapping` TO 'test_role2'
|
|
|
|
GRANT USAGE ON *.* TO 'test_role1'
|
|
|
|
GRANT USAGE ON *.* TO 'test_role2'
|
|
|
|
GRANT USAGE ON *.* TO 'test_user'@'localhost'
|
|
|
|
GRANT test_role1 TO 'test_user'@'localhost'
|
|
|
|
GRANT test_role2 TO 'test_role1'
|
|
|
|
select * from mysql.roles_mapping;
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
2013-10-18 21:27:07 +02:00
|
|
|
localhost root test_role1 Y
|
|
|
|
localhost root test_role2 Y
|
2013-10-18 21:21:10 +02:00
|
|
|
localhost test_user test_role1 N
|
2013-10-18 15:47:49 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
|
|
|
GRANT SELECT ON `mysql`.`roles_mapping` TO 'test_role2'
|
|
|
|
GRANT USAGE ON *.* TO 'test_role1'
|
|
|
|
GRANT USAGE ON *.* TO 'test_role2'
|
|
|
|
GRANT USAGE ON *.* TO 'test_user'@'localhost'
|
|
|
|
GRANT test_role1 TO 'test_user'@'localhost'
|
|
|
|
GRANT test_role2 TO 'test_role1'
|
|
|
|
use mysql;
|
|
|
|
set role none;
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
2013-10-18 18:09:08 +02:00
|
|
|
test_user@localhost NULL
|
2013-10-18 15:47:49 +02:00
|
|
|
select * from mysql.roles_mapping;
|
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table 'roles_mapping'
|
|
|
|
drop user 'test_user'@'localhost';
|
|
|
|
select * from mysql.tables_priv;
|
|
|
|
Host Db User Table_name Grantor Timestamp Table_priv Column_priv
|
|
|
|
mysql test_role2 roles_mapping root@localhost 0000-00-00 00:00:00 Select
|
2013-10-18 18:08:42 +02:00
|
|
|
revoke select on mysql.roles_mapping from test_role2;
|
2013-10-18 15:47:49 +02:00
|
|
|
delete from mysql.user where user like'test_%';
|
2013-10-18 21:19:37 +02:00
|
|
|
delete from mysql.roles_mapping where Role like 'test%';
|
2013-10-18 15:47:49 +02:00
|
|
|
flush privileges;
|