Purpose
You can use this statement to create a role. You can use roles to manage database privileges.
Required privileges
You must have the
CREATE USERprivilege. For more information about privileges in OceanBase Database, see Privilege types in MySQL mode.If the value of the system variable
read_onlyis1in the current tenant, the tenant is in read-only mode. In this case, you must also have theSUPERprivilege to execute theCREATE ROLEstatement.The system variable
read_onlyspecifies whether the tenant is in read-only mode. The default value 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 you specify this clause, a warning instead of an error message is generated when the role to be created already exists in the current tenant. |
| role_name | The name of the role to be created. Separate the names of multiple roles with commas (,). |
Examples
Create a role named
role001.obclient [test]> CREATE ROLE role001;Create the
role001androle002roles.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 warnings. The return result is as follows:+-------+------+-----------------------------------------------+ | Level | Code | Message | +-------+------+-----------------------------------------------+ | Note | 3163 | Authorization ID 'role001'@'%' already exists | +-------+------+-----------------------------------------------+ 1 row in set