mysql - 在日志文件中,慢查询日志记录更快的查询

  显示原文与译文双语对照的内容

我在数据库服务器上设置了MySQL慢查询日志,并将长查询时间设置为 5.
只检查了日志及其日志查询,只需要毫秒。 大家都知道为什么? 这里有一些日志。


I am using mysql sloq query log and set the following line in my.cnf file:
slow_query_log=1
long_query_time=5
log-output=FILE
log-queries-not-using-indexes

but my log file show like :

# User@Host: root[root] @ localhost []
# Query_time: 0.077108 Lock_time: 0.000042 Rows_sent: 0 Rows_examined: 292
SET timestamp=1389868398;
UPDATE `cp_sessions` SET `last_activity` = 1389868398 WHERE session_id = 'e9f397b37812e7e5b0563de6a32d181b';
# User@Host: root[root] @ localhost []
# Query_time: 0.022188 Lock_time: 0.000072 Rows_sent: 0 Rows_examined: 292
SET timestamp=1389868398;
UPDATE `cp_sessions` SET `last_activity` = 1389868398, `user_id` = NULL, `user_data` = 'a:3:{s:9:"game_name";s:5:"poker";s:3:"utm";N;s:5:"url_1";s:23:"http://adda52merge.org/";}' WHERE `session_id` = 'e9f397b37812e7e5b0563de6a32d181b';
# User@Host: root[root] @ localhost []
# Query_time: 0.000465 Lock_time: 0.000068 Rows_sent: 1 Rows_examined: 292
SET timestamp=1389868398;
SELECT *
FROM (`cp_sessions`)
WHERE `session_id` = '8c34926f9f6d711bdc14eeeb40b7db7b'
AND `ip_address` = '192.168.1.235'
AND `user_agent` = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko';
# User@Host: root[root] @ localhost []
# Query_time: 0.033085 Lock_time: 0.000036 Rows_sent: 0 Rows_examined: 292
SET timestamp=1389868398;
UPDATE `cp_sessions` SET `last_activity` = 1389868398 WHERE session_id = '8c34926f9f6d711bdc14eeeb40b7db7b';
# User@Host: root[root] @ localhost []
# Query_time: 0.000350 Lock_time: 0.000055 Rows_sent: 1 Rows_examined: 292
SET timestamp=1389868398;
SELECT *
FROM (`cp_sessions`)
WHERE `session_id` = '8c34926f9f6d711bdc14eeeb40b7db7b';
# User@Host: root[root] @ localhost []
# Query_time: 0.031274 Lock_time: 0.000043 Rows_sent: 0 Rows_examined: 292
SET timestamp=1389868398;
UPDATE `cp_sessions` SET `login_attempt` = 0 WHERE `session_id` = '8c34926f9f6d711bdc14eeeb40b7db7b';
# User@Host: root[root] @ localhost []
# Query_time: 0.000298 Lock_time: 0.000029 Rows_sent: 1 Rows_examined: 292
SET timestamp=1389868398;
SELECT *
FROM (`cp_sessions`)
WHERE `user_id` = '113';
# User@Host: root[root] @ localhost []
# Query_time: 0.000479 Lock_time: 0.000080 Rows_sent: 1 Rows_examined: 292
SET timestamp=1389868398;
SELECT *
FROM (`cp_sessions`)
WHERE `session_id` = '4809d7eef185f2bf3d8e38e1858a637c'
AND `ip_address` = '192.168.1.235'
AND `user_agent` = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko';
# User@Host: root[root] @ localhost []
# Query_time: 0.022236 Lock_time: 0.000037 Rows_sent: 0 Rows_examined: 292
SET timestamp=1389868398;
UPDATE `cp_sessions` SET `user_data` = '', `user_id` = 0 WHERE `user_id` = '113';

请帮助我处理错误的问题,我需要执行这个查询的时候,需要执行更多的时间。

时间: 作者:

设置 log-queries-not-using-indexes 将添加不使用索引的任何查询到慢速日志。

这应该被激活,因为它可以帮助你优化查询。

如果你想在一定的时间内查询,你可以执行

SELECT * FROM mysql.slow_log WHERE query_time> 5

这将提供执行时间超过 5秒的查询。

作者:
...