Create a role

2024-04-19 08:42:50  Updated

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 system privilege, contact the administrator. For more information, see Modify user privileges.

Syntax and examples

The SQL statement is as follows:

CREATE ROLE role_name
[ NOT IDENTIFIED
| IDENTIFIED BY password
] ;

where

  • NOT IDENTIFIED: If you specify this clause, a new role is not verified when it is enabled.

  • IDENTIFIED BY password: This clause specifies 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 the SET ROLE statement to enable the role.

  • If you do not specify the NOT IDENTIFIED or IDENTIFIED BY password clause, the NOT IDENTIFIED clause is used for a new role by default.

Examples:

  • Create the role1 role

    obclient> CREATE ROLE role1;
    Query OK, 0 rows affected
    
  • Create a role named role2 and set its password to ******

    obclient> CREATE ROLE role2 IDENTIFIED BY ******;
    Query OK, 0 rows affected
    

    For more information about the CREATE ROLE statement, see CREATE ROLE.

Contact Us