Mysql supports a config option called
When enabled (add
/etc/mysql.cnf or any included file from it), Mysql will print all the executed queries into a log file (see the specific documentation of your version to understand where the file will be written based on settings).
The general log is a useful setting to debug queries coming from the ORM when developing locally. Frameworks normally let you visualise executed queries, but ORM and the majority of queries are executed via prepared statements, and parameters are bound from the MySQL server, preventing the code to know the exact executed query.
Output general log into a table
If you need to debug on a non-local (non-prod) MySQL machine and for particular reasons you prefer to use the MySQL client itself to retrieve the log entries, you can add the setting
log_output=TABLE. Mysql will append all the executed queries into
To truncate the log:
To visualise the last 10 executed queries (last executed one first), skipping MySQL internal queries (and this query itself):
SELECT CAST(argument AS CHAR(10000) CHARACTER SET utf8) as arg
AND argument NOT LIKE '%performance_schema%'
AND argument NOT LIKE '%mysql.general_log%'
ORDER BY event_time DESC
If you are using MySQL workbench, click on the output and select Copy Field (unquoted) then paste into another tab and format to better visualise or run an EXPLAIN on it
MySQL :: MySQL 8.0 Reference Manual :: 5.4.3 The General Query Log
The general query log is a general record of what is doing. The server writes information to this log when clients…