Purpose
This statement is used to create a role. You can manage permissions through roles.
Privilege requirements
To create a role, the current user must have the
CREATE USERorCREATE ROLEprivilege. For more information about OceanBase Database privileges, see Privilege types in MySQL mode.If the value of the system variable
read_onlyis1in the current tenant, indicating that the tenant is in read-only mode, the current user must also have theSUPERprivilege to execute theCREATE ROLEstatement.The system variable
read_onlyspecifies whether the tenant is in read-only mode. By default, it is0, indicating that the tenant is in read/write mode. For more information about the system variableread_only, see read_only.
Syntax
CREATE ROLE [IF NOT EXISTS] role_name [, role_name ...];
Parameters
| Parameter | Description |
|---|---|
| IF NOT EXISTS | Optional. If this clause is specified, the system will not return an error when the role to be created already exists in the current tenant, but will instead return a warning. If this clause is not specified, an error will be returned. |
| role_name | The name of the role to be created. When creating multiple roles, separate the role names with commas (,). |
Examples
Create a role named
role001.obclient [test]> CREATE ROLE role001;Create roles named
role001androle002at the same time.obclient [test]> CREATE ROLE IF NOT EXISTS role001, role002;The return result is as follows:
Query OK, 0 rows affected, 1 warningUse the
SHOW WARNINGS;statement to query the warning information. The return result is as follows:+-------+------+-----------------------------------------------+ | Level | Code | Message | +-------+------+-----------------------------------------------+ | Note | 3163 | Authorization ID 'role001'@'%' already exists | +-------+------+-----------------------------------------------+ 1 row in set
