SHOW ERRORS

Use this MySQL statement to display error messages for the previous SQL statement. It has a COUNT(*) clause that you can use to see the number of error messages generated rather than displaying them.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

SHOW ERRORS [LIMIT [offset,] count]

SHOW COUNT(*) ERRORS

Explanation

Use this statement to display error messages for the previous SQL statement. To see the number of error messages generated by the previous SQL statement, use the COUNT(*) clause. To limit the number of error messages displayed, use the LIMIT clause. An offset can be given along with the count to specify a starting point for displaying error messages.

This statement is available as of Version 4.1 of MySQL. It will not display warnings or notes—just error messages. Use the MySQL statement, SHOW WARNINGS to get all three types of messages.

Examples

Here are a couple of examples of this MySQL statement, which were entered after an INSERT statement was entered and encountered a problem:

SHOW COUNT(*) ERRORS;

+-----------------------+
| @@session.error_count |
+-----------------------+
|                     1 | 
+-----------------------+

SHOW ERRORS;

+-------+------+-------------------------------------------------+
| Level | Code | Message                                         |
+-------+------+-------------------------------------------------+
| Error | 1136 | Column count doesn't match value count at row 2 | 
+-------+------+-------------------------------------------------+

The first statement returns the number of error messages generated by the INSERT statement. Notice that the results are stored in the session variable error_count, which is updated by each statement issued in the session. The second statement displays the error messages. This MySQL statement is perhaps more meaningful when used with an API program in which you would like to capture the error messages for a specific purpose or analysis.