You can use the CREATE ROLE statement to create a role, which you can then use to manage privileges.
Prerequisites
You have the
CREATE USERorCREATE ROLEprivilege.For more information about how to view your privileges, see View user privileges. If you do not have the required privilege, contact the administrator to obtain the privilege. For more information about how to grant privileges to a user, see Grant privileges directly.
If the system variable
read_onlyis set to1for the current tenant, which indicates that the tenant is in read-only mode, you must also have theSUPERprivilege to execute theCREATE ROLEstatement.The system variable
read_onlyspecifies whether a tenant is in read-only mode. Its default value is0, which indicates that the tenant is in read/write mode. For more information about theread_onlysystem variable, see read_only.
Example
To create a role named role1, execute the following statement:
obclient [oceanbase]> CREATE ROLE role1;
Alternatively, execute the following statement:
obclient [oceanbase]> CREATE ROLE IF NOT EXISTS role1;
In the preceding example, if you execute the statement without the IF NOT EXISTS clause, and the role1 role already exists in the tenant, an error is reported. If the IF NOT EXISTS clause is used, a warning message is returned if the error occurs.
obclient [oceanbase]> CREATE ROLE IF NOT EXISTS role1;
Query OK, 0 rows affected, 1 warning
You can query the warning message by using the SHOW WARNINGS; statement. The result is as follows:
+-------+------+---------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------+
| Note | 3163 | Authorization ID 'role1'@'%' already exists |
+-------+------+---------------------------------------------+
1 row in set
What to do next
After the role is created, you can grant other roles or privileges to it. For more information, see the following topics:
References
For more information about the CREATE ROLE statement, see CREATE ROLE.