MySQL 5.7Role function
Role functions of MySQL 5.7:
Create a user and grant the user role function:
Mysql > create user 'junior'@'127.0.0.1' identified by' 123'
Query OK, 0 rows affected (0.01 sec)
Mysql > create user 'tom'@'127.0.0.1' identified by' 123'
Query OK, 0 rows affected (0.00 sec)
Mysql > create user 'jim'@'127.0.0.1' identified by' 123'
Query OK, 0 rows affected (0.01 sec)
Mysql > grant proxy on 'junior'@'127.0.0.1' to' tom'@'127.0.0.1'
Query OK, 0 rows affected (0.01 sec)
Mysql > grant proxy on 'junior'@'127.0.0.1' to' jim'@'127.0.0.1'
Query OK, 0 rows affected (0.00 sec)
Mysql > grant select on *. * to 'junior'@'127.0.0.1'
Query OK, 0 rows affected (0.00 sec)
Mysql > show grants for 'junior'@'127.0.0.1'
+-+
| | Grants for junior@127.0.0.1 |
+-+
| | GRANT SELECT ON *. * TO 'junior'@'127.0.0.1' |
+-+
1 row in set (0.00 sec)
Mysql > show grants for 'jim'@'127.0.0.1'
+-- +
| | Grants for jim@127.0.0.1 |
+-- +
| | GRANT USAGE ON *. * TO 'jim'@'127.0.0.1' |
| | GRANT PROXY ON 'junior'@'127.0.0.1' TO' jim'@'127.0.0.1' |
+-- +
2 rows in set (0.00 sec)
Mysql > show grants for 'tom'@'127.0.0.1'
+-- +
| | Grants for tom@127.0.0.1 |
+-- +
| | GRANT USAGE ON *. * TO 'tom'@'127.0.0.1' |
| | GRANT PROXY ON 'junior'@'127.0.0.1' TO' tom'@'127.0.0.1' |
+-- +
2 rows in set (0.00 sec)
Mysql > use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-A
Database changed
Mysql > select * from proxies_priv
+-+
| | Host | User | Proxied_host | Proxied_user | With_grant | Grantor | Timestamp | |
+-+
| | localhost | root | 1 | boot@connecting host | 0000-0000: 00:00 |
| | 127.0.0.1 | tom | 127.0.0.1 | junior | 0 | root@localhost | 0000-0000: 00:00 |
| | 127.0.0.1 | jim | 127.0.0.1 | junior | 0 | root@localhost | 0000-0000: 00:00 |
+-+
3 rows in set (0.00 sec)