数据库
首页 > 数据库> > 禁止MySQL警告?

禁止MySQL警告?

作者:互联网

可以说,我执行了一个触发一些警告消息的查询:

例如:
如果存在表,则删除表;

有没有办法只抑制已触发的警告消息?

我看到有一个系统变量“ max_error_count”,将其更改为零可能会忽略警告,但也会执行所有错误/注释消息.

解决方法:

也许sql_notes变量可以帮助您解决此问题.
引用联机帮助页:

The sql_notes system variable controls whether note messages
increment warning_count and whether the server stores them. By
default, sql_notes is 1, but if set to 0, notes do not increment
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)

标签:mysql,suppress-warnings
来源: https://codeday.me/bug/20191011/1893025.html