MySQL 日志中的虚假信息
Spurious Info in MySQL Logs
我最近启用了将一般查询记录到我的本地 MySQL 服务器。
它成功了(尽管可能有点太成功了),因为日志包含很多 'spurious' 信息,我不知道这些信息是从哪里来的。它肯定不是来自我的查询。
我的查询是:
select * from CT_DATASET where ID >= 0 and ID <= 1000
在 general_log 这是我找到的:
160204 14:05:13 36 Connect root@localhost on cTLarge
36 Query /* mysql-connector-java-5.1.38 ( Revision: fe541c166cec739c74cc727c5da96c1028b4834a ) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_buffer_length AS net_buffer_length, @@net_write_timeout AS net_write_timeout, @@query_cache_size AS query_cache_size, @@query_cache_type AS query_cache_type, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@tx_isolation AS tx_isolation, @@wait_timeout AS wait_timeout
36 Query SET character_set_results = NULL
36 Query SET autocommit=1
36 Query SET net_write_timeout=600
36 Query select * from CT_DATASET where ID >= 0 and ID <= 5000000
160204 14:05:39 36 Query SET net_write_timeout=60
36 Quit
它给了我我需要的信息(在本例中是查询执行时间),但我不知道初始 SELECT 来自哪里,最好删除它(以及所有的@@parameters_x AS parameters_x 'redundant' 信息)因为它确实使日志混乱。
我如何 may/can 从日志中删除此信息(同时仍保留日志中的其他信息)
顺便说一下,相应的 'slow' 日志要简洁得多:
# Time: 160204 14:05:39
# User@Host: root[root] @ localhost [127.0.0.1] Id: 36
# Query_time: 26.232623 Lock_time: 0.000000 Rows_sent: 4929568 Rows_examined: 4929568
SET timestamp=1454591139;
select * from CT_DATASET where ID >= 0 and ID <= 5000000;
您正在使用 mysql-连接器-java-5.1.38。检查 https://dev.mysql.com/downloads/connector/j/ 处的源代码显示:
StringBuilder queryBuf = new StringBuilder(versionComment).append("SELECT");
queryBuf.append(" @@session.auto_increment_increment AS auto_increment_increment");
queryBuf.append(", @@character_set_client AS character_set_client");
queryBuf.append(", @@character_set_connection AS character_set_connection");
queryBuf.append(", @@character_set_results AS character_set_results");
queryBuf.append(", @@character_set_server AS character_set_server");
queryBuf.append(", @@init_connect AS init_connect");
queryBuf.append(", @@interactive_timeout AS interactive_timeout");
库正在执行查询并且正在正确记录。
您可以告诉 mysql 不要记录这些行。从
https://dev.mysql.com/doc/refman/5.7/en/mysql-command-options.html#option_mysql_histignore :
--histignore
A colon-separated list of one or more patterns specifying statements
to ignore for logging purposes. These patterns are added to the
default pattern list ("IDENTIFIED:PASSWORD"). The value specified
for this option affects logging of statements written to the history
file, and to syslog if the --syslog option is given. For more
information, see Section 4.5.1.3, “mysql Logging”.
我没有测试过,但你可以试试:
histignore="*IDENTIFIED*:*PASSWORD*:*mysql-connector-java*"
在您的 my.cnf 文件中。
我最近启用了将一般查询记录到我的本地 MySQL 服务器。
它成功了(尽管可能有点太成功了),因为日志包含很多 'spurious' 信息,我不知道这些信息是从哪里来的。它肯定不是来自我的查询。
我的查询是:
select * from CT_DATASET where ID >= 0 and ID <= 1000
在 general_log 这是我找到的:
160204 14:05:13 36 Connect root@localhost on cTLarge
36 Query /* mysql-connector-java-5.1.38 ( Revision: fe541c166cec739c74cc727c5da96c1028b4834a ) */SELECT @@session.auto_increment_increment AS auto_increment_increment, @@character_set_client AS character_set_client, @@character_set_connection AS character_set_connection, @@character_set_results AS character_set_results, @@character_set_server AS character_set_server, @@init_connect AS init_connect, @@interactive_timeout AS interactive_timeout, @@license AS license, @@lower_case_table_names AS lower_case_table_names, @@max_allowed_packet AS max_allowed_packet, @@net_buffer_length AS net_buffer_length, @@net_write_timeout AS net_write_timeout, @@query_cache_size AS query_cache_size, @@query_cache_type AS query_cache_type, @@sql_mode AS sql_mode, @@system_time_zone AS system_time_zone, @@time_zone AS time_zone, @@tx_isolation AS tx_isolation, @@wait_timeout AS wait_timeout
36 Query SET character_set_results = NULL
36 Query SET autocommit=1
36 Query SET net_write_timeout=600
36 Query select * from CT_DATASET where ID >= 0 and ID <= 5000000
160204 14:05:39 36 Query SET net_write_timeout=60
36 Quit
它给了我我需要的信息(在本例中是查询执行时间),但我不知道初始 SELECT 来自哪里,最好删除它(以及所有的@@parameters_x AS parameters_x 'redundant' 信息)因为它确实使日志混乱。
我如何 may/can 从日志中删除此信息(同时仍保留日志中的其他信息)
顺便说一下,相应的 'slow' 日志要简洁得多:
# Time: 160204 14:05:39
# User@Host: root[root] @ localhost [127.0.0.1] Id: 36
# Query_time: 26.232623 Lock_time: 0.000000 Rows_sent: 4929568 Rows_examined: 4929568
SET timestamp=1454591139;
select * from CT_DATASET where ID >= 0 and ID <= 5000000;
您正在使用 mysql-连接器-java-5.1.38。检查 https://dev.mysql.com/downloads/connector/j/ 处的源代码显示:
StringBuilder queryBuf = new StringBuilder(versionComment).append("SELECT");
queryBuf.append(" @@session.auto_increment_increment AS auto_increment_increment");
queryBuf.append(", @@character_set_client AS character_set_client");
queryBuf.append(", @@character_set_connection AS character_set_connection");
queryBuf.append(", @@character_set_results AS character_set_results");
queryBuf.append(", @@character_set_server AS character_set_server");
queryBuf.append(", @@init_connect AS init_connect");
queryBuf.append(", @@interactive_timeout AS interactive_timeout");
库正在执行查询并且正在正确记录。
您可以告诉 mysql 不要记录这些行。从 https://dev.mysql.com/doc/refman/5.7/en/mysql-command-options.html#option_mysql_histignore :
--histignore
A colon-separated list of one or more patterns specifying statements to ignore for logging purposes. These patterns are added to the default pattern list ("IDENTIFIED:PASSWORD"). The value specified for this option affects logging of statements written to the history file, and to syslog if the --syslog option is given. For more information, see Section 4.5.1.3, “mysql Logging”.
我没有测试过,但你可以试试:
histignore="*IDENTIFIED*:*PASSWORD*:*mysql-connector-java*"
在您的 my.cnf 文件中。