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
INSERTreports 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 forSHOW WARNINGSto return. Use SHOW LOAD for those. - An
INSERTonly filters rows when it is allowed to. Under the defaultsenable_insert_strict = trueandinsert_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_counton the OK packet carries the number of rows that were filtered or substituted, whileSHOW WARNINGSreturns a single row summarizing them. The two values are not expected to match. In MySQL,warning_countequals the number of rowsSHOW WARNINGSreturns.- The diagnostics live in the session that executed the statement. When a session is connected to a follower FE, an
INSERTis forwarded to the leader and runs there in a per-request session that is discarded when the request returns, soSHOW WARNINGSreturns an empty result on the follower, and there is no session on the leader to read them back from either. Run theINSERTfrom 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 andSHOW ERRORSis empty as well. - Diagnostics produced while reading data, such as a
CASTthat overflows and yieldsNULL, are not recorded yet.
Examples
Example 1: Read back the rows anINSERT filtered. Both session variables are needed, because under the defaults the statement fails on the first unqualified row instead of filtering it.
SHOW ERRORS reports the same code and message that were sent in the error response.