我们能知道最后一个 MySQL 错误吗?
mysqlmysqli database
为了知道最后一个 MySQL 错误,您可以使用 SHOW 命令 −
SHOW ERRORS;
或者您可以使用另一种语法 −
SHOW WARNINGS;
在这里,我们创建一个显示错误的表,然后我们将找出如何知道最后一个 MySQL 错误。在这里,错误发生是因为我们故意写了错误的创建表语句 −
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)