2013-10-18 21:21:10 +02:00
|
|
|
create user test_user@localhost;
|
|
|
|
create role test_role1;
|
|
|
|
grant test_role1 to test_user@localhost;
|
|
|
|
create role test_role2;
|
2013-10-18 21:34:44 +02:00
|
|
|
grant test_role2 to test_role1;
|
2013-10-18 05:51:10 +02:00
|
|
|
select user, host from mysql.user where user not like 'root';
|
2018-11-24 14:13:41 +01:00
|
|
|
User Host
|
2020-02-19 17:50:30 +01:00
|
|
|
mariadb.sys localhost
|
2013-10-18 21:21:10 +02:00
|
|
|
test_role1
|
|
|
|
test_role2
|
2013-10-18 05:50:24 +02:00
|
|
|
test_user localhost
|
2013-10-18 21:19:37 +02:00
|
|
|
select * from mysql.roles_mapping where User like 'test_user';
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
localhost test_user test_role1 N
|
2013-10-18 21:19:37 +02:00
|
|
|
select * from mysql.roles_mapping where User like 'test_role1';
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
|
|
|
grant select on *.* to test_role2;
|
2013-10-18 05:51:19 +02:00
|
|
|
select * from mysql.user where user like 'test_role1';
|
2018-02-12 16:26:11 +01:00
|
|
|
Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv Event_priv Trigger_priv Create_tablespace_priv Delete_history_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections plugin authentication_string password_expired is_role default_role max_statement_time
|
2017-09-08 09:22:24 +02:00
|
|
|
test_role1 N N N N N N N N N N N N N N N N N N N N N N N N N N N N N N 0 0 0 0 N Y 0.000000
|
2013-10-18 05:51:19 +02:00
|
|
|
select * from mysql.user where user like 'test_role2';
|
2018-02-12 16:26:11 +01:00
|
|
|
Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv Event_priv Trigger_priv Create_tablespace_priv Delete_history_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections plugin authentication_string password_expired is_role default_role max_statement_time
|
2017-09-08 09:22:24 +02:00
|
|
|
test_role2 Y N N N N N N N N N N N N N N N N N N N N N N N N N N N N N 0 0 0 0 N Y 0.000000
|
2013-10-18 05:50:24 +02:00
|
|
|
select * from mysql.roles_mapping;
|
2022-07-16 14:39:17 +02:00
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping`
|
2013-10-18 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
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 05:50:24 +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 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
2013-10-18 21:19:37 +02:00
|
|
|
select * from mysql.roles_mapping where Host='';
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
2013-10-18 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
2013-10-18 05:50:24 +02:00
|
|
|
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 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
2013-10-18 05:50:24 +02:00
|
|
|
select * from mysql.roles_mapping;
|
2022-07-16 14:39:17 +02:00
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping`
|
2013-10-18 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
2013-10-18 05:50:24 +02:00
|
|
|
set role test_role2;
|
2021-07-02 15:13:37 +02:00
|
|
|
ERROR OP000: User `test_user`@`localhost` has not been granted role `test_role2`
|
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 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
2013-10-18 05:50:24 +02:00
|
|
|
select * from mysql.roles_mapping;
|
2022-07-16 14:39:17 +02:00
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping`
|
2013-10-18 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
2013-10-18 05:50:24 +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 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
2013-10-18 21:19:37 +02:00
|
|
|
select * from mysql.roles_mapping where Host='';
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
2013-10-18 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
2013-10-18 05:50:24 +02:00
|
|
|
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 05:50:24 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
2013-10-18 05:50:24 +02:00
|
|
|
select * from mysql.roles_mapping;
|
2022-07-16 14:39:17 +02:00
|
|
|
ERROR 42000: SELECT command denied to user 'test_user'@'localhost' for table `mysql`.`roles_mapping`
|
2013-10-18 05:50:24 +02:00
|
|
|
delete from mysql.user where user='test_role1';
|
|
|
|
delete from mysql.user where user='test_role2';
|
2013-10-18 05:51:10 +02:00
|
|
|
delete from mysql.roles_mapping;
|
2013-10-18 05:50:24 +02:00
|
|
|
flush privileges;
|
2013-10-18 05:51:10 +02:00
|
|
|
drop user 'test_user'@'localhost';
|