The general query log is a log of every SQL query received from a client, as well as each client connect and disconnect.

Activating the general query log

The general query log is disabled by default. Since it's a record of every query received by the server, it can grow large quite quickly. If you only want a record of queries that change data, rather use the binary log instead.

To activate the general query log, set the general_log system variable to 1. The log_output server status variable determines how the output will be written, and can also disable it (see Writing logs into tables for details). If written to file, the name of the file is determined by the --general_log_file=file_name option, by default host_name.log, while the directory will be the data directory unless an absolute path is specified.

Unlike the binary log, the query log records queries in the same order that the server receives them, and not necessarily the same order that they are executed.

Example of how to log to file

By adding this to your my.cnf file all queries will be logged to the file queries.log in the datadir directory.

[[mysqld]]
general-log
general-log-file=queries.log
log-output=file

Another option is to use the log-basename (see mysqld replication options) option which ensures that all your log files (general log, replication logs etc) start with a common unique prefix. The following example will create a system.log log file.

[[mysqld]]
general-log
log-output=file
log-basename=system

Disable logging

The super user can disable logging to it for a connection by setting SQL_LOG_OFF to 1

Example

SELECT * 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
...

See also

Comments

Comments loading...