show errors 和 show warnings 显示执行语句所产生的错误、警告信息

本文将介绍 show errors 和 show warnings 显示执行语句所产生的错误、警告信息。

MySQL 的 show errors 命令可以显示执行语句所产生的错误信息,实例:

(1)执行 show errors 没有错误信息

mysql> show errors;
Empty set (0.00 sec)

(2)执行错误语句

mysql> show processlis;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'processlis' at line 1
mysql> show table;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

(3)再次执行 show errors 命令

mysql> show errors;
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                                                            |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

总结:show errors 命令将显示最后一次执行语句所产生的错误信息。

show errors 完整语法如下:

show errors [limit [offset,] row_count]

下面将演示 limit、offset 的用法。如下:

(1)我们故意执行多次错误语句,如下:

mysql> show processLis;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'processLis' at line 1
mysql> show test;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'test' at line 1
mysql> show statuss;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'statuss' at line 1
mysql> show proces;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'proces' at line 1

(2)使用 show errors list 显示错误信息

mysql> show errors limit 0,2;
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                                                                  |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'proces' at line 1 |
+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

结论:并没有显示多条错误消息,只显示了最后一条错误信息。

show warnings 完整语法如下:

show warnings [limit [offset,] row_count]

show warnings 显示最后一个执行语句所产生的警告信息,用法和 show errors 一致。

游手好闲地学习,并不比学习游手好闲好。 —— 约翰·贝勒斯
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
其他应用
公众号