SHOW WARNINGS [LIMIT [offset,] row_count]SHOW COUNT(*) WARNINGS
SHOW COUNT(*) WARNINGS;SELECT @@warning_count;
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: 3mysql> SHOW WARNINGS\G*************************** 1. row ***************************Level: WarningCode: 1265Message: Data truncated for column 'b' at row 1*************************** 2. row ***************************Level: WarningCode: 1048Message: Column 'a' cannot be null*************************** 3. row ***************************Level: WarningCode: 1264Message: Out of range value for column 'a' at row 33 rows in set (0.00 sec)
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: 3mysql> 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)
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)
mysql> \WShow warnings enabled.mysql> SELECT 1/0;+------+| 1/0 |+------+| NULL |+------+1 row in set, 1 warning (0.03 sec)Warning (Code 1365): Division by 0mysql> \wShow warnings disabled.
文章转载自数据库杂货铺,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




