Documentation Home
MySQL 9.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.0Mb
PDF (A4) - 40.1Mb
Man Pages (TGZ) - 259.0Kb
Man Pages (Zip) - 366.2Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


7.4.3 The General Query Log

The general query log is a general record of whatmysqld 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 tomysqld.

Each line that shows when a client connects also includesusingconnection_type to indicate the protocol used to establish the connection.connection_type is one ofTCP/IP (TCP/IP connection established without SSL),SSL/TLS (TCP/IP connection established with SSL),Socket (Unix socket file connection),Named Pipe (Windows named pipe connection), orShared Memory (Windows shared memory connection).

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 is in contrast with that of the binary log, for which statements are written after they are executed but before any locks are released. In addition, the query log may contain statements that only select data while such statements are never written to the binary log.

When using statement-based binary logging on a replication source server, statements received by its replicas are written to the query log of each replica. Statements are written to the query log of the source if a client reads events with themysqlbinlog utility and passes them to the server.

However, when using row-based binary logging, updates are sent as row changes rather than SQL statements, and thus these statements are never written to the query log whenbinlog_format isROW. A given update also might not be written to the query log when this variable is set toMIXED, depending on the statement used. SeeSection 19.2.1.1, “Advantages and Disadvantages of Statement-Based and Row-Based Replication”, for more information.

By default, the general query log is disabled. To specify the initial general query log state explicitly, use--general_log[={0|1}]. With no argument or an argument of 1,--general_log enables the log. With an argument of 0, this option disables the log. To specify a log file name, use--general_log_file=file_name. To specify the log destination, use thelog_output system variable (as described inSection 7.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”).

Note

If you specify theTABLE log destination, seeLog Tables andToo many open files Errors.

If you specify no name for the general query log file, the default name ishost_name.log. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

To disable or enable the general query log or change the log file name at runtime, use the globalgeneral_log andgeneral_log_file system variables. Setgeneral_log to 0 (orOFF) to disable the log or to 1 (orON) to enable it. Setgeneral_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, the server writes output to any destinations specified by thelog_output system variable. If you enable the log, the server opens the log file and writes startup messages to it. However, further logging of queries to the file does not occur unless theFILE log destination is selected. If the destination isNONE, the server writes no queries even if the general log is enabled. Setting the log file name has no effect on logging if the log destination value does not containFILE.

Server restarts and log flushing do not cause a new general query log file to be generated (although flushing closes and reopens it). To rename the file and create a new one, use the following commands:

$> mvhost_name.loghost_name-old.log$> mysqladmin flush-logs general$> mvhost_name-old.logbackup-directory

On Windows, userename rather thanmv.

You can also rename the general query log file at runtime by disabling the log:

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.

To disable or enable general query logging for the current session, set the sessionsql_log_off variable toON orOFF. (This assumes that the general query log itself is enabled.)

Passwords in statements written to the general query log are rewritten by the server not to occur literally in plain text. Password rewriting can be suppressed for the general query log by starting the server with the--log-raw option. This option may be useful for diagnostic purposes, to see the exact text of statements as received by the server, but for security reasons is not recommended for production use. See alsoSection 8.1.2.3, “Passwords and Logging”.

An implication of password rewriting is that statements that cannot be parsed (due, for example, to syntax errors) are not written to the general query log because they cannot be known to be password free. Use cases that require logging of all statements including those with errors should use the--log-raw option, bearing in mind that this also bypasses password rewriting.

Password rewriting occurs only when plain text passwords are expected. For statements with syntax that expect a password hash value, no rewriting occurs. If a plain text password is supplied erroneously for such syntax, the password is logged as given, without rewriting.

Thelog_timestamps system variable controls the time zone of timestamps in messages written to the general query log file (as well as to the slow query log file and the error log). It does not affect the time zone of general query log and slow query log messages written to log tables, but rows retrieved from those tables can be converted from the local system time zone to any desired time zone withCONVERT_TZ() or by setting the sessiontime_zone system variable.