我們可以知道最後一個 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)

更新於: 30-7-2019

249 次瀏覽

開啟你的 事業

完成課程獲得認證

開始
廣告
© . All rights reserved.