我最近启用了对我的本地MySQL服务器的常规查询记录。
这是成功的(虽然可能有点太成功),因为日志包含很多“虚假”信息,我不知道它来自哪里。它当然不是来自我的查询。
我的查询是:
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'冗余的“信息”,因为它真的使日志混乱。
我如何/可以从日志中删除此信息(同时仍保留日志中的其他信息)
顺便说一句,相应的“慢”日志更简洁:
# 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;
答案 0 :(得分:1)
您使用的是mysql-connector-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
以冒号分隔的一个或多个模式指定语句的列表 忽略用于记录目的。这些模式被添加到 默认模式列表(“ IDENTIFIED : PASSWORD ”)。指定的值 对于此选项会影响写入历史记录的语句的记录 文件,如果给出--syslog选项,则为syslog。更多 有关信息,请参见第4.5.1.3节“mysql日志记录”。
我没有测试过,但您可以尝试:
histignore="*IDENTIFIED*:*PASSWORD*:*mysql-connector-java*"
在my.cnf文件中。