• An SQLSTATE value. The value is a five-character string (for example, '42S02'). The values are
taken from ANSI SQL and ODBC and are more standardized.
A message string that provides a textual description of the error is also available.
When an error occurs, the MySQL error code, SQLSTATE value, and message string are available
using C API functions:
• MySQL error code: Call
• SQLSTATE value: Call
• Error message: Call
For prepared statements, the corresponding error functions are mysql_stmt_errno(),
mysql_stmt_sqlstate(), and mysql_stmt_error(). All error functions are described in
Section 20.6, "MySQL C
The number of errors, warnings, and notes for the previous statement can be obtained by calling
mysql_warning_count(). See
The first two characters of an SQLSTATE value indicate the error class:
• Class =
'00'
• Class =
'01'
• Class =
'02'
control what happens when a cursor reaches the end of a data set. This condition also occurs for
SELECT ... INTO var_list
• Class >
'02'
C.3. Server Error Codes and Messages
MySQL programs have access to several types of error information when the server returns an error.
For example, the
shell>
SELECT * FROM no_such_table;
ERROR 1146 (42S02): Table 'test.no_such_table' doesn't exist
The message displayed contains three types of information:
• A numeric error code (1146). This number is MySQL-specific and is not portable to other database
systems.
• A five-character SQLSTATE value ('42S02'). The values are taken from ANSI SQL and ODBC and
are more standardized. Not all MySQL error numbers have corresponding SQLSTATE values. In
these cases,
• A message string that provides a textual description of the error.
For error checking, use error codes, not error messages. Error messages do not change often, but it is
possible. Also if the database administrator changes the language setting, that affects the language of
error messages.
Error codes are stable across GA releases of a given MySQL series. Before a series reaches GA
status, new codes may still be under development and subject to change.
Server error information comes from the following source files. For details about the way that error
information is defined, see the
• Error message information is listed in the
and strings, respectively, that are substituted into the Message values when they are displayed.
Server Error Codes and Messages
mysql_errno()
mysql_sqlstate()
mysql_error()
API".
Section 20.6.6.72,
indicates success.
indicates a warning.
indicates "not found." This is relevant within the context of cursors and is used to
statements that retrieve no rows.
indicates an exception.
client program displays errors using the following format:
mysql
(general error) is used.
'HY000'
MySQL Internals
"mysql_warning_count()".
Manual.
share/errmsg.txt
2910
file.
and
represent numbers
%d
%s
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers