The general query log is a general record of what mysqld is doing. 一般查询日志是mysqld正在做的事情的一般记录。The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. 当客户端连接或断开连接时,服务器会将信息写入此日志,并记录从客户端接收的每个SQL语句。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的内容时,常规查询日志非常有用。
Each line that shows when a client connects also includes 显示客户端何时连接的每一行还包括using
to indicate the protocol used to establish the connection. connection_type
using connection_type
来指示用于建立连接的协议。connection_type
is one of TCP/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), or Shared Memory
(Windows shared memory connection).connection_type
是TCP/IP
(在没有SSL的情况下建立的TCP/IP连接)、SSL/TLS
(使用SSL建立的TCP/IP联系)、Socket
(Unix套接字文件连接)、Named Pipe
(Windows命名管道连接)或Shared Memory
(Windows共享内存连接)之一。
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. mysqld按照接收语句的顺序将语句写入查询日志,这可能与执行语句的顺序不同。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 the mysqlbinlog utility and passes them to the server.如果客户端使用mysqlbinlog实用程序读取事件并将其传递给服务器,则语句会写入源的查询日志。
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 when 但是,当使用基于行的二进制日志记录时,更新将作为行更改而不是SQL语句发送,因此当binlog_format
is ROW
. binlog_format
为ROW
时,这些语句永远不会写入查询日志。A given update also might not be written to the query log when this variable is set to 当此变量设置为MIXED
, depending on the statement used. MIXED
时,给定的更新也可能不会写入查询日志,具体取决于所使用的语句。See Section 17.2.1.1, “Advantages and Disadvantages of Statement-Based and Row-Based Replication”, for more information.有关更多信息,请参阅第17.2.1.1节,“基于语句和基于行的复制的优点和缺点”。
By default, the general query log is disabled. 默认情况下,禁用常规查询日志。To specify the initial general query log state explicitly, use 若要显式指定初始常规查询日志状态,请使用--general_log[={0|1}]
. --general_log[={0|1}]
。With no argument or an argument of 1, 如果没有参数或参数为1,--general_log
enables the log. --general_log
将启用日志。With an argument of 0, this option disables the log. 参数为0时,此选项将禁用日志。To specify a log file name, use 要指定日志文件名,请使用--general_log_file=
. file_name
--general_log_file=file_name
。To specify the log destination, use the 要指定日志目的地,请使用log_output
system variable (as described in Section 5.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”).log_output
系统变量(如第5.4.1节,“选择常规查询日志和慢速查询日志输出目的地”所述)。
If you specify the 如果指定TABLE
log destination, see Log Tables and “Too many open files” Errors.TABLE
日志目标,请参阅日志表和“打开的文件太多”错误。
If you specify no name for the general query log file, the default name is 如果没有为常规查询日志文件指定名称,则默认名称为
. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.host_name
.loghost_name.log
。服务器会在数据目录中创建文件,除非指定了一个绝对路径名来指定不同的目录。
To disable or enable the general query log or change the log file name at runtime, use the global 要在运行时禁用或启用常规查询日志或更改日志文件名,请使用全局general_log
and general_log_file
system variables. general_log
和general_log_file
系统变量。Set 将general_log
to 0 (or OFF
) to disable the log or to 1 (or ON
) to enable it. general_log
设置为0(或OFF
)以禁用日志,或将其设置为1(或ON
)以启用日志。Set 设置general_log_file
to specify the name of the log file. general_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 the 启用常规查询日志后,服务器将输出写入log_output
system variable. log_output
系统变量指定的任何目的地。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 the 但是,除非选择了FILE
log destination is selected. FILE
日志目标,否则不会将查询进一步记录到文件中。If the destination is 如果目标为NONE
, the server writes no queries even if the general log is enabled. NONE
,则即使启用了常规日志,服务器也不会写入任何查询。Setting the log file name has no effect on logging if the log destination value does not contain 如果日志目标值不包含FILE
.FILE
,则设置日志文件名对日志记录没有影响。
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:服务器重新启动和日志刷新不会导致生成新的常规查询日志文件(尽管刷新会关闭并重新打开它)。要重命名文件并创建新文件,请使用以下命令:
shell>mv
shell>host_name
.loghost_name
-old.logmysqladmin flush-logs
shell>mv
host_name
-old.logbackup-directory
On Windows, use rename rather than mv.在Windows上,使用rename而不是mv。
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 session 要禁用或启用当前会话的常规查询日志记录,请将会话sql_log_off
variable to ON
or OFF
. (This assumes that the general query log itself is enabled.)sql_log_off
变量设置为ON
或OFF
。(这假设常规查询日志本身已启用。)
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. --log-raw
选项启动服务器,可以抑制常规查询日志的密码重写。此选项可能有助于诊断,以查看服务器接收到的语句的确切文本,但出于安全原因,不建议在生产中使用。See also Section 6.1.2.3, “Passwords and Logging”.另请参见第6.1.2.3节,“密码和日志记录”。
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.--log-raw
选项,记住这也可以绕过密码重写。
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.只有当需要纯文本密码时,才会进行密码重写。对于具有期望密码哈希值的语法的语句,不会发生重写。如果为这种语法错误地提供了纯文本密码,则会按照给定的方式记录密码,而无需重写。
The log_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). log_timestamps
系统变量控制写入常规查询日志文件(以及慢速查询日志文件和错误日志)的消息中的时间戳的时区。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 with 它不会影响写入日志表的常规查询日志和慢速查询日志消息的时区,但可以使用CONVERT_TZ()
or by setting the session time_zone
system variable.CONVERT_TZ()
或设置会话time_zone
系统变量将从这些表检索到的行从本地系统时区转换为任何所需时区。