mysql.default_roles

2025-11-14 07:33:33  Updated

Note

  • In OceanBase Database V4.3.x, this view is introduced since V4.3.1.
  • In OceanBase Database V4.2.x, this view is introduced since V4.2.3.

Purpose

The mysql.default_roles view displays the roles that are enabled for a user by default.

Columns

Column Type Nullable? Description
HOST varchar(255) NO The host name of the user.
USER varchar(128) NO The username of the user.
DEFAULT_ROLE_HOST varchar(255) NO The host name of the role that is enabled by default.
DEFAULT_ROLE_USER varchar(128) NO The username of the role that is enabled by default.

Sample query

Query the roles that are enabled by default for the user001 user.

  1. Create a role named role1.

    obclient [oceanbase]> CREATE ROLE IF NOT EXISTS role1;
    Query OK, 0 rows affected, 1 warning
    
  2. Grant the ALTER SYSTEM privilege to role1.

    obclient [oceanbase]> GRANT ALTER SYSTEM ON *.* TO role1;
    
  3. Create a user named user001.

    obclient [oceanbase]> CREATE USER 'user001'@'%' IDENTIFIED BY '******';
    
  4. Grant role1 to user001.

    obclient [oceanbase]>GRANT role001 TO user001 WITH ADMIN OPTION;;
    
  5. Specify to enable all roles granted to the user001 user at login.

    obclient > SET DEFAULT ROLE ALL TO user001;
    
  6. Query the roles that are enabled by default for the user001 user.

    obclient > SELECT * FROM mysql.default_roles;
    

    The query result is as follows:

    +------+---------+-------------------+-------------------+
    | HOST | USER    | DEFAULT_ROLE_HOST | DEFAULT_ROLE_USER |
    +------+---------+-------------------+-------------------+
    | %    | user001 | %                 | role001           |
    +------+---------+-------------------+-------------------+
    1 row in set (0.001 sec)
    

References

Contact Us