You can execute the CREATE ROLE statement to create roles and grant privileges to these roles for role-based privilege management.
Prerequisites
You have the CREATE ROLE system privilege. For more information about how to view your privileges, see View user privileges. If you do not have the CREATE ROLE privilege, contact the administrator to obtain the privilege. For more information about how to grant privileges to a user, see Grant direct privileges.
Syntax and examples
The SQL syntax is as follows:
CREATE ROLE role_name
[ NOT IDENTIFIED
| IDENTIFIED BY password
] ;
where:
If the
NOT IDENTIFIEDclause is specified, a new role is not verified when it is enabled.IDENTIFIED BY passwordspecifies the password to enable a role. If you specify this clause and grant the role to a user, the user must specify the password in theSET ROLEstatement to enable the role.If you do not specify the
NOT IDENTIFIEDorIDENTIFIED BY passwordclause, theNOT IDENTIFIEDclause is used for a new role by default.
Here is an example:
Create a role named
role1.obclient> CREATE ROLE role1; Query OK, 0 rows affectedCreate a role named
role2and set its password to******.obclient> CREATE ROLE role2 IDENTIFIED BY ******; Query OK, 0 rows affectedFor more information about the
CREATE ROLEstatement, see CREATE ROLE.