How to suppress warnings in MySQL?


To suppress warnings, set SQL_NOTES=0. Let us see an example.

At first, we will set SQL_NOTES to 1 −

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

Now, let us drop a table which does not exist. As you can see a warning message is now visible −

mysql> drop table if exists web.DemoTable;
Query OK, 0 rows affected, 1 warning (0.07 sec)

To look at the above warning message, you need to just use the SHOW WARNINGS command −

mysql> show warnings;

This will produce the following output displaying the warning message −

+-------+------+-----------------------------------+
| Level | Code | Message                           |
+-------+------+-----------------------------------+
| Note  | 1051 | Unknown table 'web.DemoTable'     |
+-------+------+-----------------------------------+
1 row in set (0.00 sec)

Now, since we need to suppress warnings, use SQL_NOTES and set it to OFF −

mysql> SET sql_notes = 0;
Query OK, 0 rows affected (0.00 sec)

Let us drop the above table once again −

mysql> drop table if exists web.DemoTable;
Query OK, 0 rows affected (0.07 sec)

The above process is called suppress warning in MySQL. Now, when you will again try to fetch the warnings, it will display “Empty set” as shown below −

mysql> show warnings;
Empty set (0.00 sec)

Updated on: 30-Sep-2019

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements