4.5.1.3 mysql Client Logging客户端日志记录

The mysql client can do these types of logging for statements executed interactively:mysql客户端可以对交互执行的语句进行以下类型的日志记录:

The following discussion describes characteristics that apply to all logging types and provides information specific to each logging type.以下讨论描述了适用于所有日志记录类型的特征,并提供了每种日志记录类型特有的信息。

How Logging Occurs日志记录是如何发生的

For each enabled logging destination, statement logging occurs as follows:对于每个启用的日志记录目标,语句日志记录按如下方式进行:

Consequently, an input statement that spans multiple lines can be logged twice. Consider this input:因此,跨越多行的输入语句可以被记录两次。考虑以下输入:

mysql> SELECT
    -> 'Today is'
    -> ,
    -> CURDATE()
    -> ;

In this case, mysql logs the SELECT, 'Today is', ,, CURDATE(), and ; lines as it reads them. It also logs the complete statement, after mapping SELECT\n'Today is'\n,\nCURDATE() to SELECT 'Today is' , CURDATE(), plus a delimiter. 在这种情况下,mysql在读取“SELECT”、“'Today is'”、“,”、“CURDATE()”和“;”行时会记录这些行。在将SELECT\n'Today is'\n,\nCURDATE()映射到SELECT 'Today is' , CURDATE()以及一个分隔符之后,它还会记录完整的语句。Thus, these lines appear in logged output:因此,这些行出现在日志输出中:

SELECT
'Today is'
,
CURDATE()
;
SELECT 'Today is' , CURDATE();

mysql ignores for logging purposes statements that match any pattern in the ignore list. mysql忽略与“ignore”列表中的任何模式匹配的语句用于日志记录。By default, the pattern list is "*IDENTIFIED*:*PASSWORD*", to ignore statements that refer to passwords. 默认情况下,模式列表为"*IDENTIFIED*:*PASSWORD*",忽略涉及密码的语句。Pattern matching is not case-sensitive. Within patterns, two characters are special:模式匹配不区分大小写。在模式中,有两个字符是特殊的:

To specify additional patterns, use the --histignore option or set the MYSQL_HISTIGNORE environment variable. 要指定其他模式,请使用--histignore选项或设置MY_RESHISTIGNORE环境变量。(If both are specified, the option value takes precedence.) The value should be a list of one or more colon-separated patterns, which are appended to the default pattern list.(如果同时指定了这两个选项,则选项值优先。)该值应该是一个或多个冒号分隔的模式列表,这些模式将附加到默认模式列表中。

Patterns specified on the command line might need to be quoted or escaped to prevent your command interpreter from treating them specially. 命令行上指定的模式可能需要引用或转义,以防止命令解释器对其进行特殊处理。For example, to suppress logging for UPDATE and DELETE statements in addition to statements that refer to passwords, invoke mysql like this:例如,除了引用密码的语句外,要抑制UPDATEDELETE语句的日志记录,请按如下方式调用mysql

mysql --histignore="*UPDATE*:*DELETE*"
Controlling the History File控制历史文件

The .mysql_history file should be protected with a restrictive access mode because sensitive information might be written to it, such as the text of SQL statements that contain passwords. .mysql_history文件应使用限制访问模式进行保护,因为敏感信息可能会写入其中,例如包含密码的SQL语句文本。See Section 6.1.2.1, “End-User Guidelines for Password Security”. 请参阅第6.1.2.1节,“密码安全最终用户指南”Statements in the file are accessible from the mysql client when the up-arrow key is used to recall the history. 当使用向上箭头键调用历史记录时,可以从mysql客户端访问文件中的语句。See Disabling Interactive History.请参阅禁用交互历史记录

If you do not want to maintain a history file, first remove .mysql_history if it exists. Then use either of the following techniques to prevent it from being created again:如果您不想维护历史文件,请先删除.mysql_history(如果存在)。然后使用以下任何一种技术来防止再次创建它:

syslog Logging Characteristicssyslog日志记录特性

If the --syslog option is given, mysql writes interactive statements to the system logging facility. 如果给出了--syslog选项,mysql会将交互式语句写入系统日志记录工具。Message logging has the following characteristics.消息日志记录具有以下特征。

Logging occurs at the information level. This corresponds to the LOG_INFO priority for syslog on Unix/Linux syslog capability and to EVENTLOG_INFORMATION_TYPE for the Windows Event Log. 日志记录发生在“信息”级别。这对应于Unix/Linux系统日志功能的系统日志的LOG_INFO优先级,以及Windows事件日志的EVENTLOG_INFORMATION_TYPEConsult your system documentation for configuration of your logging capability.有关日志记录功能的配置,请参阅系统文档。

Message size is limited to 1024 bytes.消息大小限制为1024字节。

Messages consist of the identifier MysqlClient followed by these values:消息由标识符MysqlClient和以下值组成:

Here is a sample of output generated on Linux by using --syslog. This output is formatted for readability; each logged message actually takes a single line.以下是在Linux上使用--syslog生成的输出示例。此输出的格式是为了可读性;每条记录的消息实际上只需要一行。

Mar  7 12:39:25 myhost MysqlClient[20824]:
  SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,
  DB_SERVER:'127.0.0.1', DB:'--', QUERY:'USE test;'
Mar  7 12:39:28 myhost MysqlClient[20824]:
  SYSTEM_USER:'oscar', MYSQL_USER:'my_oscar', CONNECTION_ID:23,
  DB_SERVER:'127.0.0.1', DB:'test', QUERY:'SHOW TABLES;'