Can we know the last MySQL error?

MySQLMySQLi Database

In order to know the last MySQL error, you can use SHOW command −

SHOW ERRORS;

Or you can use another syntax −

SHOW WARNINGS;

Here, we are creating a table that displays an error and then we will find out how to know the last MySQL error. Here, the error occurs because we have intentionally written incorrect create table statement −

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

Following is the query to know the last MySQL error −

mysql> SHOW ERRORS;

This will produce the following output −

+-------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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)
raja
Published on 30-Apr-2019 07:10:17
Advertisements