Suppress MySQL warnings?

纵饮孤独 提交于 2019-12-20 03:07:24

问题


Lets say, I have executed a query that triggers some warning messages:

eg:
DROP TABLE IF EXISTS "abcd";

Is there a way to suppress only warning message that been triggering?

I see there is a system variable "max_error_count", changing it to zero may ignore warnings but it would also do all errors/note messages.


回答1:


Maybe the sql_notes variable helps you with this problem. Quote from the manpage:

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)


来源:https://stackoverflow.com/questions/27616564/suppress-mysql-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!