Appendix B Errors, Error Codes, and Common Problems

Table of Contents

B.1 Error Message Sources and Components
B.2 Error Information Interfaces
B.3 Error Message Reference
B.3.1 Server Error Message Reference
B.3.2 Client Error Message Reference
B.3.3 Global Error Message Reference
B.4 Problems and Common Errors
B.4.1 How to Determine What Is Causing a Problem
B.4.2 Common Errors When Using MySQL Programs
B.4.3 Administration-Related Issues
B.4.4 Query-Related Issues
B.4.5 Optimizer-Related Issues
B.4.6 Table Definition-Related Issues
B.4.7 Known Issues in MySQL

This appendix describes the types of error information MySQL provides and how to obtain information about them. It also lists the error messages that the MySQL server and MySQL client programs generate. The final section is for troubleshooting. It describes common problems and errors that may occur and potential resolutions.

Additional Resources

Other sections that discuss error-related topics include:

B.1 Error Message Sources and Components

This section discusses how error messages originate within MySQL and the components they contain.

Error Message Sources

Error messages can originate on the server side or the client side:

  • On the server side, error messages may occur during the startup and shutdown processes, as a result of issues that occur during SQL statement execution, and so forth.

    • The MySQL server writes some error messages to its error log. These indicate issues of interest to database administrators or that require DBA action.

    • The server sends other error messages to client programs. These indicate issues pertaining only to a particular client. The MySQL client library takes errors received from the server and makes them available to the host client program.

  • Client-side error messages are generated from within the MySQL client library, usually involving problems communicating with the server.

Example server-side error messages written to the error log:

  • This message produced during the startup process provides a status or progress indicator:

    2018-10-28T13:01:32.735983Z 0 [Note] [MY-010303] [Server] Skipping
    generation of SSL certificates as options related to SSL are specified.
    
  • This message indicates an issue that requires DBA action:

    2018-10-02T03:20:39.410387Z 768 [ERROR] [MY-010045] [Server] Event Scheduler:
    [evtuser@localhost][myschema.e_daily] Unknown database 'mydb'
    

Example server-side error message sent to client programs, as displayed by the mysql client:

mysql> SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist

Example client-side error message originating from within the client library, as displayed by the mysql client:

shell> mysql -h no-such-host
ERROR 2005 (HY000): Unknown MySQL server host 'no-such-host' (0)

Whether an error originates from within the client library or is received from the server, a MySQL client program may respond in varying ways. As just illustrated, the client may display the error message so the user can take corrective measures. The client may instead internally attempt to resolve or retry a failed operation, or take other action.

Error Message Components

When an error occurs, error information includes several components: an error code, SQLSTATE value, and message string. These components have the following characteristics:

  • Error code: This value is numeric. It is MySQL-specific and is not portable to other database systems.

    Each error number has a corresponding symbolic value. Examples:

    The set of error codes used in error messages is partitioned into distinct ranges; see Error Code Ranges.

    Error codes are stable across General Availability (GA) releases of a given MySQL series. Before a series reaches GA status, new codes may still be under development and are subject to change.

  • SQLSTATE value: This value is a five-character string (for example, '42S02'). SQLSTATE values are taken from ANSI SQL and ODBC and are more standardized than the numeric error codes. The first two characters of an SQLSTATE value indicate the error class:

    • Class = '00' indicates success.

    • Class = '01' indicates a warning.

    • Class = '02' indicates not found. This is relevant within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. This condition also occurs for SELECT ... INTO var_list statements that retrieve no rows.

    • Class > '02' indicates an exception.

    For server-side errors, not all MySQL error numbers have corresponding SQLSTATE values. In these cases, 'HY000' (general error) is used.

    For client-side errors, the SQLSTATE value is always 'HY000' (general error), so it is not meaningful for distinguishing one client error from another.

  • Message string: This string provides a textual description of the error.

Error Code Ranges

The set of error codes used in error messages is partitioned into distinct ranges, each with its own purpose:

  • 1 to 999: Global error codes. This error code range is called global because it is a shared range that is used by the server as well as by clients.

    When an error in this range originates on the server side, the server writes it to the error log, padding the error code with leading zeros to six digits and adding a prefix of MY-.

    When an error in this range originates on the client side, the client library makes it available to the client program with no zero-padding or prefix.

  • 1,000 to 1,999: Server error codes reserved for messages sent to clients.

  • 2,000 to 2,999: Client error codes reserved for use by the client library.

  • 3,000 to 4,999: Server error codes reserved for messages sent to clients.

  • 5,000 to 5,999: Error codes reserved for use by X Plugin for messages sent to clients.

  • 10,000 to 49,999: Server error codes reserved for messages to be written to the error log (not sent to clients).

    When an error in this range occurs, the server writes it to the error log, padding the error code with leading zeros to six digits and adding a prefix of MY-.

  • 50,000 to 51,999: Error codes reserved for use by third parties.

The server handles error messages written to the error log differently from error messages sent to clients:

  • When the server writes a message to the error log, it pads the error code with leading zeros to six digits and adds a prefix of MY- (examples: MY-000022, MY-010048).

  • When the server sends a message to a client program, it adds no zero-padding or prefix to the error code (examples: 1036, 3013).

B.2 Error Information Interfaces

Error messages can originate on the server side or the client side, and each error message includes an error code, SQLSTATE value, and message string, as described in Section B.1, “Error Message Sources and Components”. For lists of server-side, client-side, and global (shared between server and clients) errors, see Section B.3, “Error Message Reference”.

For error checking from within programs, use error code numbers or symbols, not error message strings. Message strings do not change often, but it is possible. Also, if the database administrator changes the language setting, that affects the language of message strings; see Section 10.11, “Setting the Error Message Language”.

Error information in MySQL is available in the server error log, at the SQL level, from within client programs, and at the command line.

Error Log

On the server side, some messages are intended for the error log. For information about configuring where and how the server writes the log, see Section 5.4.2, “The Error Log”.

Other server error messages are intended to be sent to client programs and are available as described in Client Error Message Interface.

The range within which a particular error code lies determines whether the server writes an error message to the error log or sends it to clients. For information about these ranges, see Error Code Ranges.

SQL Error Message Interface

At the SQL level, there are several sources of error information in MySQL:

Client Error Message Interface

Client programs receive errors from two sources:

  • Errors that originate on the client side from within the MySQL client library.

  • Errors that originate on the server side and are sent to the client by the server. These are received within the client library, which makes them available to the host client program.

The range within which a particular error code lies determines whether it originated from within the client library or was received by the client from the server. For information about these ranges, see Error Code Ranges.

Regardless of whether an error originates from within the client library or is received from the server, a MySQL client program obtains the error code, SQLSTATE value, message string, and other related information by calling C API functions in the client library:

For descriptions of the client library error functions, see Section 28.7, “MySQL C API”.

A MySQL client program may respond to an error in varying ways. The client may display the error message so the user can take corrective measures, internally attempt to resolve or retry a failed operation, or take other action. For example, (using the mysql client), a failure to connect to the server might result in this message:

shell> mysql -h no-such-host
ERROR 2005 (HY000): Unknown MySQL server host 'no-such-host' (0)

Command-Line Error Message Interface

The perror program provides information from the command line about error numbers. See Section 4.8.2, “perror — Display MySQL Error Message Information”.

shell> perror 1231
MySQL error code MY-001231 (ER_WRONG_VALUE_FOR_VAR): Variable '%-.64s'
can't be set to the value of '%-.200s'

For MySQL NDB Cluster errors, use ndb_perror. See Section 22.4.16, “ndb_perror — Obtain NDB Error Message Information”.

shell> ndb_perror 323
NDB error code 323: Invalid nodegroup id, nodegroup already existing:
Permanent error: Application error

B.3 Error Message Reference

This section provides a reference for the various types of error messages in MySQL:

B.3.1 Server Error Message Reference

The MySQL server writes some error messages to its error log, and sends others to client programs.

Example server-side error messages written to the error log:

2018-10-28T13:01:32.735983Z 0 [Note] [MY-010303] [Server] Skipping
generation of SSL certificates as options related to SSL are specified.

2018-10-02T03:20:39.410387Z 768 [ERROR] [MY-010045] [Server] Event Scheduler:
[evtuser@localhost][myschema.e_daily] Unknown database 'mydb'

Example server-side error message sent to client programs, as displayed by the mysql client:

mysql> SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist

Each server error message includes an error code, SQLSTATE value, and message string, as described in Section B.1, “Error Message Sources and Components”. These components are available as described in Section B.2, “Error Information Interfaces”.

In addition to the errors in the following list, the server can also produce error messages that have error codes in the range from 1 to 999. See Section B.3.3, “Global Error Message Reference”