Enable the MySQL general query log
Capture client SQL in a MySQL table or file, preserve existing logging settings, and switch off a diagnostic capture when it is no longer needed.
Enable general_log when you need a short record of what clients send to MySQL. log_output chooses a table, a file, or both. Recording starts when logging is enabled; it does not reconstruct earlier traffic.
Capture to a table
First record the current settings so you can restore them:
SELECT @@GLOBAL.general_log, @@GLOBAL.log_output,
@@GLOBAL.general_log_file;
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
Reproduce the issue, stop the temporary capture, and inspect recent entries:
SET GLOBAL general_log = 'OFF';
SELECT event_time, user_host, command_type, argument
FROM mysql.general_log
ORDER BY event_time DESC
LIMIT 20;
If logging was already enabled for another purpose, restore its earlier configuration instead of leaving it off. Changing log_output also changes the slow-query log destination.
Capture to a file
SET GLOBAL log_output = 'FILE';
SET GLOBAL general_log_file = '/var/log/mysql/all-queries.log';
SET GLOBAL general_log = 'ON';
Set the path before starting the capture and verify that the server account can write it. Appropriate administrative privileges are required for these global changes.
For a configuration that survives restart:
[mysqld]
log_output = FILE
general_log = ON
general_log_file = /var/log/mysql/mysql.log
Persistent full logging should be a deliberate operational choice, with retention, permissions, and storage monitoring. Runtime SET GLOBAL alone does not edit this option file.
Understand what the log proves
The general log records connection activity and statements received by the server, including reads. It does not establish that each statement completed or succeeded, and its ordering reflects receipt rather than completion.
Every captured statement adds work and storage. Application SQL may contain credentials or personal data even though MySQL rewrites passwords in certain account-management statements. Keep access restricted and avoid assuming the log is fully redacted.
To stop a capture that you enabled temporarily:
SET GLOBAL general_log = 'OFF';
Narrow the investigation when possible
For expensive queries, consider the slow query log:
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1;
The threshold is in seconds. Its global value applies to new connections; existing sessions retain their own values. Check the output destination and capture volume as well.
Can I filter the general log to one table? There is no built-in per-table capture filter. A query such as WHERE argument LIKE '%orders%' can help inspect retained text, but matches comments and similarly named objects too; it is not a SQL-aware filter.
See the MySQL general query log reference.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan