Purpose
This statement is used to create a role. You can use roles to manage permissions.
Privilege requirements
The current user must have the
CREATE USERorCREATE ROLEprivilege to create a role. For more information about OceanBase AI Database privileges, see Permission classification.If the value of the system variable
read_onlyfor the current tenant is1, meaning the tenant is in read-only mode, the current user must also have theSUPERprivilege to execute theCREATE ROLEstatement.The system variable
read_onlyis used to set whether a tenant is in read-only mode. The default value is0, which indicates 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
Parameters |
Description |
|---|---|
| IF NOT EXISTS | Optional. If this clause is specified, the system will issue a warning if the role to be created already exists in the current tenant, but no error will be returned. If this clause is not specified, an error will be returned. |
| role_name | Specifies the name of the role to be created. When creating multiple roles, separate the role names with commas (,). |
Examples
Create the role
role001.obclient [test]> CREATE ROLE role001;Create the roles
role001androle002simultaneously.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 warning information. The return result is as follows:+-------+------+-----------------------------------------------+ | Level | Code | Message | +-------+------+-----------------------------------------------+ | Note | 3163 | Authorization ID 'role001'@'%' already exists | +-------+------+-----------------------------------------------+ 1 row in set