#### 13.7.7.42 SHOW WARNINGS Statement

[]()[]()

```
SHOW WARNINGS [LIMIT [offset,] row_count]
SHOW COUNT(*) WARNINGS
```

[`SHOW WARNINGS`](show-warnings.html) is a diagnostic statement that displays information about the conditions (errors, warnings, and notes) resulting from executing a statement in the current session. Warnings are generated for DML statements such as [`INSERT`](insert.html), [`UPDATE`](update.html), and [`LOAD DATA`](load-data.html) as well as DDL statements such as [`CREATE TABLE`](create-table.html) and [`ALTER TABLE`](alter-table.html).

 The `LIMIT` clause has the same syntax as for the [`SELECT`](select.html) statement. See [Section 13.2.10, “SELECT Statement”](select.html).

[`SHOW WARNINGS`](show-warnings.html) is also used following [`EXPLAIN`](explain.html), to display the extended information generated by [`EXPLAIN`](explain.html). See [Section 8.8.3, “Extended EXPLAIN Output Format”](explain-extended.html).

[`SHOW WARNINGS`](show-warnings.html) displays information about the conditions resulting from execution of the most recent nondiagnostic statement in the current session. If the most recent statement resulted in an error during parsing, [`SHOW WARNINGS`](show-warnings.html) shows the resulting conditions, regardless of statement type (diagnostic or nondiagnostic).

 The [`SHOW COUNT(*) WARNINGS`](show-warnings.html) diagnostic statement displays the total number of errors, warnings, and notes. You can also retrieve this number from the [`warning_count`](server-system-variables.html#sysvar_warning_count) system variable:

```
SHOW COUNT(*) WARNINGS;
SELECT @@warning_count;
```

 A difference in these statements is that the first is a diagnostic statement that does not clear the message list. The second, because it is a [`SELECT`](select.html) statement is considered nondiagnostic and does clear the message list.

 A related diagnostic statement, [`SHOW ERRORS`](show-errors.html), shows only error conditions (it excludes warnings and notes), and [`SHOW COUNT(*) ERRORS`](show-warnings.html) statement displays the total number of errors. See [Section 13.7.7.17, “SHOW ERRORS Statement”](show-errors.html). [`GET DIAGNOSTICS`](get-diagnostics.html) can be used to examine information for individual conditions. See [Section 13.6.7.3, “GET DIAGNOSTICS Statement”](get-diagnostics.html).

 Here is a simple example that shows data-conversion warnings for [`INSERT`](insert.html). The example assumes that strict SQL mode is disabled. With strict mode enabled, the warnings would become errors and terminate the [`INSERT`](insert.html).

```
mysql> CREATE TABLE t1 (a TINYINT NOT NULL, b CHAR(4));
Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO t1 VALUES(10,'mysql'), (NULL,'test'), (300,'xyz');
Query OK, 3 rows affected, 3 warnings (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 3

mysql> SHOW WARNINGS\G
*************************** 1. row ***************************
  Level: Warning
   Code: 1265
Message: Data truncated for column 'b' at row 1
*************************** 2. row ***************************
  Level: Warning
   Code: 1048
Message: Column 'a' cannot be null
*************************** 3. row ***************************
  Level: Warning
   Code: 1264
Message: Out of range value for column 'a' at row 3
3 rows in set (0.00 sec)
```

 The [`max_error_count`](server-system-variables.html#sysvar_max_error_count) system variable controls the maximum number of error, warning, and note messages for which the server stores information, and thus the number of messages that [`SHOW WARNINGS`](show-warnings.html) displays. To change the number of messages the server can store, change the value of [`max_error_count`](server-system-variables.html#sysvar_max_error_count).

[`max_error_count`](server-system-variables.html#sysvar_max_error_count) controls only how many messages are stored, not how many are counted. The value of [`warning_count`](server-system-variables.html#sysvar_warning_count) is not limited by [`max_error_count`](server-system-variables.html#sysvar_max_error_count), even if the number of messages generated exceeds [`max_error_count`](server-system-variables.html#sysvar_max_error_count). The following example demonstrates this. The [`ALTER TABLE`](alter-table.html) statement produces three warning messages (strict SQL mode is disabled for the example to prevent an error from occuring after a single conversion issue). Only one message is stored and displayed because [`max_error_count`](server-system-variables.html#sysvar_max_error_count) has been set to 1, but all three are counted (as shown by the value of [`warning_count`](server-system-variables.html#sysvar_warning_count)):

```
mysql> SHOW VARIABLES LIKE 'max_error_count';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_error_count | 1024  |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> SET max_error_count=1, sql_mode = '';
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER TABLE t1 MODIFY b CHAR;
Query OK, 3 rows affected, 3 warnings (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 3

mysql> SHOW WARNINGS;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1263 | Data truncated for column 'b' at row 1 |
+---------+------+----------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT @@warning_count;
+-----------------+
| @@warning_count |
+-----------------+
|               3 |
+-----------------+
1 row in set (0.01 sec)
```

 To disable message storage, set [`max_error_count`](server-system-variables.html#sysvar_max_error_count) to 0. In this case, [`warning_count`](server-system-variables.html#sysvar_warning_count) still indicates how many warnings occurred, but messages are not stored and cannot be displayed.

 The [`sql_notes`](server-system-variables.html#sysvar_sql_notes) system variable controls whether note messages increment [`warning_count`](server-system-variables.html#sysvar_warning_count) and whether the server stores them. By default, [`sql_notes`](server-system-variables.html#sysvar_sql_notes) is 1, but if set to 0, notes do not increment [`warning_count`](server-system-variables.html#sysvar_warning_count) and the server does not store them:

```
mysql> SET sql_notes = 1;
mysql> DROP TABLE IF EXISTS test.no_such_table;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+-------+------+------------------------------------+
| Level | Code | Message                            |
+-------+------+------------------------------------+
| Note  | 1051 | Unknown table 'test.no_such_table' |
+-------+------+------------------------------------+
1 row in set (0.00 sec)

mysql> SET sql_notes = 0;
mysql> DROP TABLE IF EXISTS test.no_such_table;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW WARNINGS;
Empty set (0.00 sec)
```

 The MySQL server sends to each client a count indicating the total number of errors, warnings, and notes resulting from the most recent statement executed by that client. From the C API, this value can be obtained by calling [`mysql_warning_count()`](https://dev.mysql.com/doc/c-api/8.0/en/mysql-warning-count.html). See [mysql\_warning\_count()](https://dev.mysql.com/doc/c-api/8.0/en/mysql-warning-count.html).

 In the [**mysql**](mysql.html) client, you can enable and disable automatic warnings display using the `warnings` and `nowarning` commands, respectively, or their shortcuts, `\W` and `\w` (see [Section 4.5.1.2, “mysql Client Commands”](mysql-commands.html)). For example:

```
mysql> \W
Show warnings enabled.
mysql> SELECT 1/0;
+------+
| 1/0  |
+------+
| NULL |
+------+
1 row in set, 1 warning (0.03 sec)

Warning (Code 1365): Division by 0
mysql> \w
Show warnings disabled.
```

