OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.5

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Activate a role

    Last Updated:2026-04-09 09:38:52  Updated
    Share
    What is on this page
    Specify the roles that become active by default when a user logs in
    Prerequisites
    Examples of using the SET DEFAULT ROLE statement
    Examples of using the ALTER USER statement
    Use the activate_all_roles_on_login variable
    Specify the roles that become active in the current session
    References

    folded

    Share

    A user can be granted multiple roles. After a role is granted to a user, the user can use the privileges of the role only when the role is active in a session. You can use the CURRENT_ROLE() function to query the active roles in the current session.

    By default, roles granted to a user or role from another user or role are not automatically activated in a session.

    Specify the roles that become active by default when a user logs in

    The MySQL mode of OceanBase Database allows you to specify the roles of a user that become active by default when the user logs in by using the SET DEFAULT ROLE statement or the ALTER USER statement with the DEFAULT ROLE clause.

    Prerequisites

    Notice

    If a role is already granted to a user, you can specify to activate the role by default when you log in as the user without further authorization.

    • The user has the roles to be activated.

    • The user has the CREATE USER privilege.

    Examples of using the SET DEFAULT ROLE statement

    You can specify to activate the roles of one or more users in one SET DEFAULT ROLE statement.

    • Specify to deactivate all roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> SET DEFAULT ROLE NONE TO test1;
      

      To deactivate all roles granted to the test1 and test2 users by default when they log in, execute the following statement:

      obclient [oceanbase]> SET DEFAULT ROLE NONE TO test1,test2;
      
    • Specify to activate all roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> SET DEFAULT ROLE ALL TO test1;
      
    • Specify to activate the employee and developer roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> SET DEFAULT ROLE employee,developer TO test1;
      

    Examples of using the ALTER USER statement

    You can specify to activate the roles of only one user in each ALTER USER statement.

    • Specify to deactivate all roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> ALTER USER test1 DEFAULT ROLE NONE;
      
    • Specify to activate all roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> ALTER USER test1 DEFAULT ROLE ALL;
      
    • Specify to activate the employee and developer roles granted to the test1 user by default when the user logs in.

      obclient [oceanbase]> ALTER USER test1 DEFAULT ROLE employee,developer;
      

    Use the activate_all_roles_on_login variable

    If a user has the ALTER SYSTEM privilege, you can use the global variable activate_all_roles_on_login to specify to automatically activate all roles granted to the user when the user logs in. The default value of the variable is off, which specifies to not activate any roles granted to a user when the user logs in.

    When you set the variable, observe the following notes:

    • If you set the activate_all_roles_on_login variable to on, the system ignores the SET DEFAULT ROLE or ALTER USER statement, and automatically activates all roles granted to a user by default when the user logs in.

    • If you set the activate_all_roles_on_login variable to off, the system automatically activates the roles specified by the SET DEFAULT ROLE or ALTER USER statement when the user logs in.

    You can set the activate_all_roles_on_login variable to on by using the following statement:

    obclient [oceanbase]> SET GLOBAL activate_all_roles_on_login = on;
    

    Specify the roles that become active in the current session

    OceanBase Database in MySQL mode allows you to specify the roles granted to the current user that become active in the current session by using the SET ROLE statement.

    Note

    The SET ROLE statement takes effect only in the current session.

    Here are some examples:

    • Specify to maintain the default role settings in the current session.

      obclient [oceanbase]> SET ROLE DEFAULT;
      

      After the statement is executed, the system activates roles based on the value of the activate_all_roles_on_login variable and the settings of the SET DEFAULT ROLE or ALTER USER statement.

      • If the activate_all_roles_on_login variable is set to on, the system activates all roles granted to the user in the current session.

      • If the activate_all_roles_on_login variable is set to off, the system activates the roles specified by the SET DEFAULT ROLE or ALTER USER statement in the current session.

    • Specify to deactivate all roles granted to the current user in the current session.

      obclient [oceanbase]> SET ROLE NONE;
      
    • Specify to activate all roles granted to the current user in the current session.

      obclient [oceanbase]> SET ROLE ALL;
      
    • Specify to activate all roles granted to the current user other than the role1 role in the current session.

      obclient [oceanbase]> SET ROLE ALL EXCEPT role1;
      

      You can specify multiple roles that you want to exclude.

    • Specify to activate the employee and developer roles in the current session.

      obclient [oceanbase]> SET ROLE employee,developer;
      

    References

    View roles

    Previous topic

    Grant a role to a user or another role
    Last

    Next topic

    View roles
    Next
    What is on this page
    Specify the roles that become active by default when a user logs in
    Prerequisites
    Examples of using the SET DEFAULT ROLE statement
    Examples of using the ALTER USER statement
    Use the activate_all_roles_on_login variable
    Specify the roles that become active in the current session
    References