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

    Enable security audit

    Last Updated:2026-04-09 09:38:52  Updated
    Share
    What is on this page
    Audit scope
    Limitations and considerations
    Create filters
    Syntax
    Examples
    Configure filters
    Syntax
    Examples
    Enable security audit

    folded

    Share

    This topic describes how to audit specific events by using a series of filters.

    Applicability

    This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support security audit.

    Audit scope

    A filter can filter events by account, event type, and event attribute, and determine whether to audit the events that meet the filter conditions.

    Limitations and considerations

    • An expression must be placed directly and uniquely in an output column of a SELECT statement without being limited by a parent expression. The output column is an item specified in the SELECT statement.
    • You cannot write expressions in subqueries.
    • After you define a filter, you must configure it for a user to make it take effect.
    • One filter corresponds to multiple users. You can configure one filter for multiple users, but one user can have only one filter.
    • You must specify an audit filter for a session when you create it. The audit filter applies to the session throughout its lifecycle.

    Create filters

    You can create a filter to enable the audit mode for a MySQL tenant. The filter can filter audit events by event type. At present, you can create three types of filters to specify to record all events, record none of the events, and record only logins and logouts.

    Syntax

    You can use the AUDIT_LOG_FILTER_SET_FILTER function to create a filter. The syntax is as follows:

    AUDIT_LOG_FILTER_SET_FILTER('filter_name', 'definition_of_filters');
    

    The following table describes the fields in the syntax.

    Field
    Description
    filter_name The name of the filter.

    Note

    The AUDIT_LOG_FILTER_SET_FILTER function adopts the CREATE OR REPLACE semantics. It overwrites an existing object when you perform a DDL operation on the object.

    definition_of_filters The definition of the audit filter, which is expressed in the JSON format. The filter design principle in the current version is compatible with that of MySQL. However, a filter can filter audit events only by event type.

    At present, you can create three types of filters:

    • A filter to specify to record all events

      {
      "filter": {
          "log": true
      }
      }
      

      or

      {
      "filter": {
          "log": true,
          "class": [
          { "name": "connection" },
          { "name": "general" },
          { "name": "table_access" }
          ]
      }
      }
      
    • A filter to specify to record none of the events

      {
      "filter": {
          "log": false
      }
      }
      
    • A filter to specify to record only logins and logouts

       {
      "filter": {
          "log": true,
          "class": [
          { "name": "connection" }
          ]
      }
      }
      

    The following table describes the types of audit events.

    Event type
    Description
    connection A login/logout.
    table_access Execution of a DML statement.
    general A parser error of a CMD command.

    Examples

    Create a filter named log_all to specify to record all events.

    obclient [test]>SELECT AUDIT_LOG_FILTER_SET_FILTER('log_all', '{ "filter": { "log": true } }');
    
    • If the DDL operation is successful, the expression returns OK.

      +-------------------------------------------------------------------------+
      | AUDIT_LOG_FILTER_SET_FILTER('log_all', '{ "filter": { "log": true } }') |
      +-------------------------------------------------------------------------+
      | OK                                                                      |
      +-------------------------------------------------------------------------+
      1 row in set
      
    • If the DDL operation fails, the SELECT statement is still successfully executed, and the expression outputs an error message.

      obclient [test]>SELECT AUDIT_LOG_FILTER_SET_FILTER('log_err', '1');
      

      The return result is as follows:

      +---------------------------------------------+
      | AUDIT_LOG_FILTER_SET_FILTER('log_err', '1') |
      +---------------------------------------------+
      | ERROR: JSON parsing error.                  |
      +---------------------------------------------+
      1 row in set
      

    You can query the mysql.audit_log_filter view for the definitions of audit filters.

    obclient [test]> select * from mysql.audit_log_filter;
    

    The return result is as follows:

    +---------+-------------------------------+
    | NAME    | FILTER                        |
    +---------+-------------------------------+
    | log_all | { "filter": { "log": true } } |
    +---------+-------------------------------+
    1 row in set (0.003 sec)
    

    The following table describes the fields in the syntax.

    Field
    Description
    NAME The name of the filter.
    FILTER The definition of the filter.

    Configure filters

    You must configure a filter for a user before the background thread can generate audit logs.

    Syntax

    You can use the AUDIT_LOG_FILTER_SET_USER function to configure a filter for a user.

    AUDIT_LOG_FILTER_SET_USER('user_name', 'filter_name');
    

    The following table describes the fields in the syntax.

    Field
    Description
    user_name The username.

    Note

    The value of user@host specified in the AUDIT_LOG_FILTER_SET_USER function is not necessarily the name of an existing user. It can be a wildcard character or the name of a user that does not exist. It a user that does not exist is specified, it will be used in login audit. Take note of the following limitations when specifying user_name:

    • You can use a wildcard character, namely %, to replace only the entire user_name field.
    • You cannot specify the host field, or use a wildcard character to replace only a part of the user_name field, for example, test_%. If host is specified or a value like test_% is used for user_name, the filter cannot be created.

    filter_name The name of the filter.

    Note

    The AUDIT_LOG_FILTER_SET_USER function adopts the CREATE OR REPLACE semantics. It overwrites an existing object when you perform a DDL operation on the object. If the filter specified by filter_name does not exist, the DDL operation neither takes effect nor returns an error.

    Examples

    Configure the log_all filter for the user001 user.

    obclient [test]> SELECT AUDIT_LOG_FILTER_SET_USER('user001', 'log_all');
    
    • If the DDL operation is successful, the expression returns OK.

      +-------------------------------------------------+
      | AUDIT_LOG_FILTER_SET_USER('user001', 'log_all') |
      +-------------------------------------------------+
      | OK                                              |
      +-------------------------------------------------+
      1 row in set
      
    • If the DDL operation fails, the SELECT statement is still successfully executed, and the expression outputs an error message.

      obclient [test]>SELECT AUDIT_LOG_FILTER_SET_USER('log_err', '1');
      

      The return result is as follows:

      +--------------------------------------------+
      | AUDIT_LOG_FILTER_SET_USER('log_err', '1')  |
      +--------------------------------------------+
      | ERROR: Invalid character in the user name. |
      +--------------------------------------------+
      1 row in set (0.001 sec)
      

    You can query the mysql.audit_log_user view for the mappings between audit filters and users.

    obclient [test]> select * from mysql.audit_log_user;
    

    The return result is as follows:

    +---------+------+------------+
    | USER    | HOST | FILTERNAME |
    +---------+------+------------+
    | user001 | %    | log_all    |
    +---------+------+------------+
    1 row in set (0.003 sec)
    

    The following table describes the fields in the syntax.

    Field
    Description
    USER The username.
    HOST The name of the host.
    FILTERNAME The name of the filter.

    Enable security audit

    You can use the audit_log_enable parameter to specify whether to enable security audit in a MySQL tenant.

    obclient> ALTER SYSTEM SET audit_log_enable=TRUE;
    

    Previous topic

    Overview
    Last

    Next topic

    Set audit rules
    Next
    What is on this page
    Audit scope
    Limitations and considerations
    Create filters
    Syntax
    Examples
    Configure filters
    Syntax
    Examples
    Enable security audit