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.
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 . For example:
It can also be set in a server in an prior to starting up the server. For example:
By default, the general query log is written to ${hostname}.log in the directory. However, this can be changed.
One way to configure the general query log filename is to set the system variable. It can be changed dynamically with . For example:
It can also be set in a server in an prior to starting up the server. For example:
If it is a relative path, then the is relative to the directory.
However, the system variable can also be an absolute path. For example:
Another way to configure the general query log filename is to set the option, which configures MariaDB to use a common prefix for all log files (e.g. general query log, , , , 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 in an prior to starting up the server. For example:
The cannot be an absolute path. The log file name is relative to the directory.
The general query log can either be written to a file on disk, or it can be written to the table in the database. To choose the general query log output destination, set the system variable.
The general query log is output to a file by default. However, it can be explicitly chosen by setting the system variable to FILE. It can be changed dynamically with . For example:
It can also be set in a server in an prior to starting up the server. For example:
The general query log can either be written to the table in the database by setting the system variable to TABLE. It can be changed dynamically with . For example:
It can also be set in a server in an prior to starting up the server. For example:
Some rows in this table might look like this:
See for more information.
A user with the privilege can disable logging to the general query log for a connection by setting the system variable to 1. For example:
In and later, it is possible to disable logging to the general query log for specific types of statements by setting the system variable. This option cannot be set dynamically. It can be set in a server in an prior to starting up the server. For example:
Unix and Linux distributions offer the utility, which makes it very easy to rotate log files. See for more information on how to use this utility to rotate the general query log.
This page is licensed: CC BY-SA / Gnu FDL
SET GLOBAL general_log=1;[mariadb]
...
general_logSET GLOBAL general_log_file='mariadb.log';[mariadb]
...
general_log
general_log_file=mariadb.log[mariadb]
...
general_log
general_log_file=/var/log/mysql/mariadb.log[mariadb]
...
log-basename=mariadb
general_logSET GLOBAL log_output='FILE';[mariadb]
...
log_output=FILE
general_log
general_log_file=queries.logSET GLOBAL log_output='TABLE';[mariadb]
...
log_output=TABLE
general_logSELECT * FROM mysql.general_log\G
*************************** 1. row ***************************
event_time: 2014-11-11 08:40:04.117177
user_host: root[root] @ localhost []
thread_id: 74
server_id: 1
command_type: Query
argument: SELECT * FROM test.s
*************************** 2. row ***************************
event_time: 2014-11-11 08:40:10.501131
user_host: root[root] @ localhost []
thread_id: 74
server_id: 1
command_type: Query
argument: SELECT * FROM mysql.general_log
...SET SESSION SQL_LOG_OFF=1;[mariadb]
...
log_output=FILE
general_log
general_log_file=queries.log
log_disabled_statements='slave,sp'