The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.
mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data.)
Control the general query log as follows:
Before 5.1.6, the general query log destination is always a
file. To enable the log, start mysqld with
the
--log[=
or file_name
]-l [
option.
file_name
]
As of MySQL 5.1.6, the destination can be a file or a table,
or both. Start mysqld with the
--log[=
or file_name
]-l [
option to enable the general query log, and optionally use
file_name
]--log-output
to specify the log
destination (as described in Section 5.2.1, “Selecting General Query and Slow Query Log Output Destinations”).
As of MySQL 5.1.12, as an alternative to
--log
or -l
,
use --general_log[={0|1}]
to
specify the initial general query log state. In this case, the
default general query log file name is used. With no argument
or an argument of 1,
--general_log
enables the log.
With an argument of 0, this option disables the log.
As of MySQL 5.1.29, use
--general_log[={0|1}]
to enable
or disable the general query log, and optionally
--general_log_file=
to specify a log file name. The
file_name
--log
and -l
options are deprecated.
If you specify no name for the general query log file, the default
name is
in
the data directory. If you specify a file name that is not an
absolute path name, the server writes the file in the data
directory.
host_name
.log
For runtime control of the general query log, use the global
general_log
and
general_log_file
system
variables. Set general_log
to 0
(or OFF
) to disable the log or to 1 (or
ON
) to enable it. Set
general_log_file
to specify the
name of the log file. If a log file already is open, it is closed
and the new file is opened.
When the general query log is enabled, output is written to any
destinations specified by the
--log-output
option or
log_output
system variable. If
you enable the log, the server opens the log file and writes
startup messages to it. However, logging of queries to the file
does not occur unless the FILE
log destination
is selected. If the destination is NONE
, no
queries are written even if the general log is enabled. Setting
the log file name has no effect on logging if the log destination
value does not contain FILE
.
Server restarts and log flushing do not cause a new general query log file to be generated (although flushing closes and reopens it). On Unix, you can rename the file and create a new one by using the following commands:
shell>mv
shell>host_name
.loghost_name
-old.logmysqladmin flush-logs
shell>cp
shell>host_name
-old.logbackup-directory
rm
host_name
-old.log
Before 5.1.3, you cannot rename a log file on Windows while the
server has it open. You must stop the server and rename the file,
and then restart the server to create a new log file. As of 5.1.3,
this applies only to the error log. However, a stop and restart
can be avoided by using
FLUSH LOGS
, which
causes the server to rename the error log with an
-old
suffix and open a new error log.
As of MySQL 5.1.12, you can disable the general query log at runtime:
SET GLOBAL general_log = 'OFF';
With the log disabled, rename the log file externally; for example, from the command line. Then enable the log again:
SET GLOBAL general_log = 'ON';
This method works on any platform and does not require a server restart.
The session sql_log_off
variable
can be set to ON
or OFF
to
disable or enable general query logging for the current
connection.
The general query log should be protected because logged statements might contain passwords. See Section 5.5.6.1, “Administrator Guidelines for Password Security”.
User Comments
Add your own comment.