Zum Hauptinhalt springen

Debugging

Logging all performed queries to MySQL​

By default SQL queries are not logged for performance and memory saving reasons. If we need to log queries for debugging, we can activate general query log.

In MySQL/MariaDB we first check if general query log is enabled:

SHOW VARIABLES LIKE 'general_log%';

This outputs the status and the file where it logs to:

+------------------+------------+
| Variable_name | Value |
+------------------+------------+
| general_log | OFF |
| general_log_file | femas1.log |
+------------------+------------+

We can find out the path of the log file with:

SHOW VARIABLES LIKE 'datadir';

We can activate general log with:

SET GLOBAL general_log = 1;

However it's recommended to keep it disabled:

SET GLOBAL general_log = 0;

More useful for production is the slow query log, which logs only slow queries:

SET GLOBAL slow_query_log = 1;
SET GLOBAL long_query_time = 1; -- in seconds