MySQL 可以了解最后一次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)
阅读更多:MySQL 教程
极客教程