Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knowing the last mysql error

I run a PHP script which does a lot of mysql work

At some point mysql fails, without printing any errors

I'd like to go then to mysql from console, and ask it what was the last error.

How can I do it?

(I'm aware of php's mysql_error(), but I'm looking for mysql command that I can run directly independently of a php script)

like image 511
shealtiel Avatar asked May 09 '11 02:05

shealtiel


People also ask

How can I see MySQL errors?

The SHOW COUNT(*) ERRORS statement displays the number of errors. You can also retrieve this number from the error_count variable: SHOW COUNT(*) ERRORS; SELECT @@error_count; SHOW ERRORS and error_count apply only to errors, not warnings or notes.

How do I show SQL errors returned by MySQL server?

We can print the error message by using mysql function mysql_error(). This function returns the error message associated with most recently executed query.

Where are MySQL error logs stored?

The MySQL server uses the error log to record information relevant to the error that prevents the server from starting. The error log is located in the data directory specified in your my. ini file.

How do I view MySQL logs?

log or mysqld. log. The data directory will typically be /var/lib/mysql/ or something similar, and it will serve as the default destination for any logs that are enabled without an alternate path. The log settings are managed via a user-editable configuration file such as /etc/mysql/mysql.


1 Answers

You can run

SHOW ERRORS;

And a similar useful one is:

SHOW WARNINGS;

EDIT

Apparently this will only show errors (or warnings) from your own sessions. So I guess it will not suit your purpose (using console to find errors caused by php).

Anyway, you can read the manual for more info (it says nothing about cross session error logging): http://dev.mysql.com/doc/refman/5.0/en/show-warnings.html

like image 170
Galz Avatar answered Nov 08 '22 20:11

Galz