General Query Log
The general query log is a log of every SQL query received from a client, as well as each client connect and disconnect. Since it's a record of every query received by the server, it can grow large quite quickly.
However, if you only want a record of queries that change data, it might be better to use the binary log instead. One important difference is that the binary log only logs a query when the transaction is committed by the server, but the general query log logs a query immediately when it is received by the server.
Enabling the General Query Log
The general query log is disabled by default.
To enable the general query log, set the general_log system variable to 1
. It can be changed dynamically with SET GLOBAL. For example:
It can also be set in a server option group in an option file prior to starting up the server. For example:
Configuring the General Query Log Filename
By default, the general query log is written to ${hostname}.log
in the datadir directory. However, this can be changed.
One way to configure the general query log filename is to set the general_log_file system variable. It can be changed dynamically with SET GLOBAL. For example:
It can also be set in a server option group in an option file prior to starting up the server. For example:
If it is a relative path, then the general_log_file is relative to the datadir directory.
However, the general_log_file system variable can also be an absolute path. For example:
Another way to configure the general query log filename is to set the log-basename option, which configures MariaDB to use a common prefix for all log files (e.g. general query log, slow query log, error log, binary logs, etc.). The general query log filename will be built by adding a .log
extension to this prefix. This option cannot be set dynamically. It can be set in a server option group in an option file prior to starting up the server. For example:
The log-basename cannot be an absolute path. The log file name is relative to the datadir directory.
Choosing the General Query Log Output Destination
The general query log can either be written to a file on disk, or it can be written to the general_log table in the mysql database. To choose the general query log output destination, set the log_output system variable.
Writing the General Query Log to a File
The general query log is output to a file by default. However, it can be explicitly chosen by setting the log_output system variable to FILE
. It can be changed dynamically with SET GLOBAL. For example:
It can also be set in a server option group in an option file prior to starting up the server. For example:
Writing the General Query Log to a Table
The general query log can either be written to the general_log table in the mysql database by setting the log_output system variable to TABLE
. It can be changed dynamically with SET GLOBAL. For example:
It can also be set in a server option group in an option file prior to starting up the server. For example:
Some rows in this table might look like this:
See Writing logs into tables for more information.
Disabling the General Query Log for a Session
A user with the SUPER privilege can disable logging to the general query log for a connection by setting the SQL_LOG_OFF system variable to 1
. For example:
Disabling the General Query Log for Specific Statements
In MariaDB 10.3.1 and later, it is possible to disable logging to the general query log for specific types of statements by setting the log_disabled_statements system variable. This option cannot be set dynamically. It can be set in a server option group in an option file prior to starting up the server. For example:
Rotating the General Query Log on Unix and Linux
Unix and Linux distributions offer the logrotate utility, which makes it very easy to rotate log files. See Rotating Logs on Unix and Linux for more information on how to use this utility to rotate the general query log.
See Also
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?