第102回ではMySQL 8.
mandatory_roles
mandatory_
mysql> SET PERSIST mandatory_roles = 'ro_role'; Query OK, 0 rows affected (0.01 sec) mysql> show variables like 'mandatory_roles'; +-----------------+---------+ | Variable_name | Value | +-----------------+---------+ | mandatory_roles | ro_role | +-----------------+---------+ 1 row in set (0.05 sec)
またmandatory_
mysql> revoke ro_role from 'test_user'@'localhost'; ERROR 3628 (HY000): The role `ro_role`@`%` is a mandatory role and can't be revoked or dropped. The restriction can be lifted by excluding the role identifier from the global variable mandatory_roles.
activate_all_roles_on_login
activate_
もし、
mysql> show variables like 'activate_all_roles_on_login'; +-----------------------------+-------+ | Variable_name | Value | +-----------------------------+-------+ | activate_all_roles_on_login | ON | +-----------------------------+-------+ 1 row in set (0.01 sec)
ROLEまわりの実行権限
MySQL 8.
権限名 | 内容 |
---|---|
CREATE ROLE | CREATE ROLE構文でROLEを作成する権限 |
DROP ROLE | DROP ROLE構文でROLEを削除する権限 |
ROLE_ |
GRANT構文によるROLEの付与、 |
もし、
mysql> CREATE ROLE rw_role; ERROR 1396 (HY000): Operation CREATE ROLE failed for 'rw_role'@'%'
ただし、
ROLEの運用
ROLEを運用していくうえでできるようになることを確認していきます。
新たなユーザーへのROLEの付与
MySQL 5.
MySQL 8.
mysql> CREATE USER test_user@'%' IDENTIFIED BY 'test_user' DEFAULT ROLE rw_role; Query OK, 0 rows affected (0.00 sec) mysql> SHOW GRANTS FOR test_user@'%'; +----------------------------------------+ | Grants for test_user@% | +----------------------------------------+ | GRANT USAGE ON *.* TO `test_user`@`%` | | GRANT `rw_role`@`%` TO `test_user`@`%` | +----------------------------------------+ 2 rows in set (0.00 sec)
ROLEの継承について
ROLEに別のROLEを付与することで、
defaultのROLEの確認
接続したユーザーがデフォルトでどのようなROLEが付与されるかは、
mysql> SELECT * FROM default_roles; +-----------+-----------+-------------------+-------------------+ | HOST | USER | DEFAULT_ROLE_HOST | DEFAULT_ROLE_USER | +-----------+-----------+-------------------+-------------------+ | % | test_user | % | rw_role | | 127.0.0.1 | test_user | % | rw_role | +-----------+-----------+-------------------+-------------------+ 2 rows in set (0.01 sec)
まとめ
第102回、