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 *note error-message-elements::. For lists of server-side, client-side, and global (shared between server and clients) errors, see MySQL 5.7 Error Message Reference (https://dev.mysql.com/doc/mysql-errors/5.7/en/).
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 *note 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.
*note error-interface-log::
*note error-interface-sql::
*note error-interface-client::
*note error-interface-command::
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 *note error-log::.
Other server error messages are intended to be sent to client programs and are available as described in *note error-interface-client::.
SQL Error Message Interface
At the SQL level, there are several sources of error information in MySQL:
SQL statement warning and error information is available through the note 'SHOW WARNINGS': show-warnings. and note 'SHOW ERRORS': show-errors. statements. The 'warning_count' system variable indicates the number of errors, warnings, and notes (with notes excluded if the 'sql_notes' system variable is disabled). The 'error_count' system variable indicates the number of errors. Its value excludes warnings and notes.
The note 'GET DIAGNOSTICS': get-diagnostics. statement may be used to inspect the diagnostic information in the diagnostics area. See note get-diagnostics::.
*note 'SHOW SLAVE STATUS': show-slave-status. statement output includes information about replication errors occurring on replica servers.
note 'SHOW ENGINE INNODB STATUS': show-engine. statement output includes information about the most recent foreign key error if a note 'CREATE TABLE': create-table. statement for an *note 'InnoDB': innodb-storage-engine. table fails.
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.
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:
'mysql_errno()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-errno.html) returns the MySQL error code.
'mysql_sqlstate()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-sqlstate.html) returns the SQLSTATE value.
'mysql_error()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-error.html) returns the message string.
'mysql_stmt_errno()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-stmt-errno.html), 'mysql_stmt_sqlstate()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-stmt-sqlstate.html), and 'mysql_stmt_error()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-stmt-error.html) are the corresponding error functions for prepared statements.
'mysql_warning_count()' (https://dev.mysql.com/doc/c-api/5.7/en/mysql-warning-count.html) returns the number of errors, warnings, and notes for the most recent statement.
For descriptions of the client library error functions, see MySQL 5.7 C API Developer Guide (https://dev.mysql.com/doc/c-api/5.7/en/).
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 *note 'mysql': mysql. client), a failure to connect to the server might result in this message:
$> mysql -h no-such-host
ERROR 2005 (HY000): Unknown MySQL server host 'no-such-host' (0)
Command-Line Error Message Interface
The note 'perror': perror. program provides information from the command line about error numbers. See note perror::.
$> perror 1231
MySQL error code 1231 (ER_WRONG_VALUE_FOR_VAR): Variable '%-.64s' can't
be set to the value of '%-.200s'
For MySQL NDB Cluster errors, use note 'ndb_perror': mysql-cluster-programs-ndb-perror. See note mysql-cluster-programs-ndb-perror::.
$> ndb_perror 323
NDB error code 323: Invalid nodegroup id, nodegroup already existing:
Permanent error: Application error
File: manual.info.tmp, Node: problems, Prev: error-interfaces, Up: error-handling