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.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive 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.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    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

    Error handling specifications for MySQL-compatible applications

    Last Updated:2026-04-02 06:23:56  Updated
    share
    What is on this page
    Obtain error information
    Java driver library
    libmysql C driver library
    Error handling specifications
    Error codes unique to OceanBase Database
    MySQL-compatible error codes

    folded

    share

    This topic describes the error handling specifications for MySQL-compatible applications.

    OceanBase Database V1.0 and later are fully compatible with MySQL Database. OceanBase Database also strives to maintain consistency with MySQL Database in terms of error codes, SQLSTATE, and error messages. Therefore, according to our product design principles, application error handling can refer to MySQL Database's handling specifications. However, as a distributed database, OceanBase Database has fundamental differences from a standalone MySQL database, and some errors unique to distributed environments cannot be expressed using MySQL Database's error codes. Generally, if the value of an error code is greater than 4000, the error code is unique to OceanBase Database; if the error code's value is within 4000, it is a compatible error code of MySQL Database. For the complete list of error codes supported by the MySQL-compatible mode of OceanBase Database on the server side, see Overview of error messages.

    In addition to errors returned by the database server, applications may also detect errors that are returned locally by the driver library, such as database connection failures. Applications that use MySQL-compatible tenants of OceanBase Database can use MySQL driver libraries, such as the MySQL JDBC Driver. OceanBase Database is fully compatible with MySQL Database for these error codes. The value range of these client error codes is typically 2000 to 3000.

    Obtain error information

    Drivers in different languages provide different APIs to obtain error information. For more information about each driver, see the OceanBase Database documentation and MySQL Database documentation.

    Java driver library

    When a Java application that uses JDBC fails to execute an SQL statement, an SQLException can be captured. The exception contains the error code, SQLSTATE value, and error message. For more information about SQLException, see JDBC API documentation.

    Methods for capturing an SQLException are as follows:

    • Call getErrorCode() to obtain the error code.
    • Call getSQLState() to obtain the SQLSTATE value.
    • Call getMessage() to obtain the error message.

    libmysql C driver library

    When a C application that uses libmysql fails to execute an SQL statement, you can obtain the error information by using the following methods:

    • Call mysql_errno() to obtain the error code.
    • Call mysql_sqlstate() to obtain the SQLSTATE value.
    • Call mysql_error() to obtain the error message.

    Error handling specifications

    Most errors in the MySQL-compatible mode of OceanBase Database do not need to be handled by applications and can be directly returned. For fault tolerance and application robustness, the following four different strategies can be used for error handling based on the scenario and error type:

    1. Strategy 1: Handle errors based on the statement type.

      • If a timeout error occurs during execution of a SELECT statement, the statement can be retried because the retry operation has no side effect.

      • If a timeout error occurs during remote or distributed execution of a modification statement such as UPDATE, the transaction must be rolled back because whether the statement is successfully executed is uncertain. If the statement is idempotent, it can be retried.

      • If a timeout error occurs during execution of a COMMIT or ROLLBACK statement, the error is directly returned because the transaction status is unknown.

    2. Strategy 2: If an error occurs during execution of any statement, roll back the current transaction and then retry it.

    3. Strategy 3: If an error occurs during execution of any statement, retry the current statement.

    4. Strategy 4: If an error occurs during execution of any statement, close the current connection and then reestablish the connection.

    Error codes unique to OceanBase Database

    The following table describes common runtime error codes unique to OceanBase Database. Applications can handle such errors by using strategies suggested for corresponding error codes.

    Error code
    SQLSTATE
    Description
    Statement execution result
    Transaction status
    Handling strategy
    4012 HY000 Execution timed out. Unknown Unknown Strategy 1
    4038 HY000 The current replica is not the leader and cannot provide services. This error may occur when the leader is switched. Failed Unchanged Strategy 3
    4138 HY000 The version of the read snapshot is outdated. Failed Unchanged Strategy 3
    4225 HY000 The partition does not exist. This error may occur when a partition is migrated. Failed Unchanged Strategy 3
    6002 40000 The transaction is rolled back in the system. Failed Rolled back Strategy 2
    6231 HY000 Replica data is unreadable. This error may occur when a replica is migrated. Failed Unchanged Strategy 3
    6235 25000 The current transaction cannot be serialized. This error may occur when concurrent transactions conflict at the repeatable read (RR) and serializable isolation levels.
    For more information about transaction isolation levels, see Overview of transaction isolation levels.
    Failed Unchanged Strategy 2
    8001 to 8004 08004 The connection cannot be recovered. Failed Unknown Strategy 4

    MySQL-compatible error codes

    For MySQL-compatible error codes with a value less than 4000, follow the same handling methods as those for MySQL Database. In particular, applications need to pay attention to the following error codes.

    Error code
    SQLSTATE
    Description
    Handling strategy
    1205 HY000 A deadlock is found. Roll back the current transaction and retry it.
    1213 40001 Lock wait timeout occurs. Roll back the current transaction and retry it.

    Previous topic

    Error code introduction
    Last

    Next topic

    Disconnected from the server, with ERROR 2013 reported
    Next
    What is on this page
    Obtain error information
    Java driver library
    libmysql C driver library
    Error handling specifications
    Error codes unique to OceanBase Database
    MySQL-compatible error codes