Skip to main content
SHOW WARNINGS displays the diagnostics (notes, warnings, and errors) generated by the most recently executed statement on the current session. SHOW ERRORS is the same statement but returns only the error-level diagnostics. These statements implement the MySQL diagnostics area, so a MySQL client, or a JDBC driver through Statement.getWarnings(), can retrieve the diagnostics of the previous statement. Two things fill the buffer: an INSERT that filtered rows or substituted out-of-range values with NULL instead of failing, and the error of a statement that failed. No privilege is required to perform this operation.

Syntax

Parameters

LIMIT [offset,] row_count: returns at most row_count diagnostics, skipping the first offset ones. offset is optional and defaults to 0.

Return value

Usage notes

The buffer holds the diagnostics of the previous statement and is replaced when the next statement begins execution, or with its own error when a statement fails, including a statement that fails to parse. Three statement classes leave the buffer unchanged when they succeed: SET, BEGIN / COMMIT / ROLLBACK, and SHOW, which covers SHOW WARNINGS and SHOW ERRORS themselves. SHOW WARNINGS can therefore be issued repeatedly, and still returns the diagnostics of the last INSERT after a COMMIT. Switching database with USE replaces the buffer as well, whether the client sends it as a statement or as the MySQL COM_INIT_DB command.
  • Only an INSERT reports filtered rows this way. Broker Load, Spark Load and Routine Load are asynchronous jobs that the submitting statement merely registers, and Stream Load has no SQL session at all, so none of them leaves anything for SHOW WARNINGS to return. Use SHOW LOAD for those.
  • An INSERT only filters rows when it is allowed to. Under the defaults enable_insert_strict = true and insert_max_filter_ratio = 0, a single unqualified row fails the statement instead, and the buffer then holds that error rather than a warning. See the first example.
  • warning_count on the OK packet carries the number of rows that were filtered or substituted, while SHOW WARNINGS returns a single row summarizing them. The two values are not expected to match. In MySQL, warning_count equals the number of rows SHOW WARNINGS returns.
  • The diagnostics live in the session that executed the statement. When a session is connected to a follower FE, an INSERT is forwarded to the leader and runs there in a per-request session that is discarded when the request returns, so SHOW WARNINGS returns an empty result on the follower, and there is no session on the leader to read them back from either. Run the INSERT from a session connected to the leader FE, or open the tracking URL carried in the message. A forwarded statement that fails behaves the same way: the follower relays the leader’s error response without the error code, so it records nothing and SHOW ERRORS is empty as well.
  • Diagnostics produced while reading data, such as a CAST that overflows and yields NULL, are not recorded yet.

Examples

Example 1: Read back the rows an INSERT filtered. Both session variables are needed, because under the defaults the statement fails on the first unqualified row instead of filtering it.
Example 2: Return at most one diagnostic.
Example 3: Read back the error of a statement that failed. SHOW ERRORS reports the same code and message that were sent in the error response.