我们可以知道最后一个 MySQL 错误吗?
为了了解最后一个 MySQL 错误,可以使用 SHOW 命令 −
SHOW ERRORS;
或者可以使用另一个语法 −
SHOW WARNINGS;
在此,我们创建一个显示错误的表,然后我们将会找出如何了解最后一个 MySQL 错误。此处,错误发生是因为我们故意编写了不正确的 create table 语句 −
mysql> create table DemoTable(Id int); 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 'create table DemoTable(Id int)' at line 1
以下是了解最后一个 MySQL 错误的查询 −
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 'create table DemoTable(Id int)' at line 1 | +-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
广告