Grant a role to a user or another role

2025-01-02 01:58:41  Updated

This topic describes how to grant a role to a user or another role. You cannot grant a role to itself. Circular role granting is not supported.

You can grant one or more roles to one or more users or roles.

Prerequisites

You have the roles to be granted and the ADMIN OPTION privilege. For more information about how to view your privileges, see View user privileges.

Examples

Grant a role to a user

  • Grant the employee role to the test1 user and allow the user to grant the role to other users or roles.

    obclient [oceanbase]> GRANT employee TO test1 WITH ADMIN OPTION;
    

    In this example, the WITH ADMIN OPTION clause specifies whether the role can be granted to other roles or users.

  • Grant the employee role to the test1 and test2 users.

    obclient [oceanbase]> GRANT employee TO test1,test2;
    
  • Grant the employee and developer roles to the test1 user.

    obclient [oceanbase]> GRANT employee,developer TO test1;
    

Grant a role to another role

  • Grant the employee role to the role1 role, and allow the role1 role to grant the employee role to other roles or users.

    obclient [oceanbase]> GRANT employee TO role1 WITH ADMIN OPTION;
    

    In this example, the WITH ADMIN OPTION clause specifies whether the role can be granted to other roles or users.

  • Grant the employee role to the role1 and role2 roles.

    obclient [oceanbase]> GRANT employee TO role1,role2;
    
  • Grant the employee and developer roles to the role1 role.

    obclient [oceanbase]> GRANT employee,developer TO role1;
    

What to do next

To use the privileges of a granted role, the granted role must be activated. For information about how to activate a role, see Activate a role.

References

For more information about the GRANT statement, see GRANT.

Contact Us