簡體   English   中英

為什么mysql慢日志記錄這些非慢查詢

[英]Why does mysql slow log reports these non-slow queries

我的mysql服務器已配置了long_query_time = 2但我仍然看到慢查詢日志中報告的這些查詢看起來很快速:

# Time: 120730  5:06:41
# User@Host: <user> @ <Host> [<IP>] 
# Query_time: 0.000412  Lock_time: 0.000060 Rows_sent: 5  Rows_examined: 5
SET timestamp=1343639201;
SELECT album_id FROM `TB_albums` where album_id!='res_4fe4333271bda7.42833845' and deleted is NULL order by `created_time` desc limit 5;

如您所見,Query_time:0.000412 Lock_time:0.000060似乎在2秒以下

您是否知道為什么要報告這些“ 快速 ”查詢?

MySQL還記錄不使用索引的查詢

my.cnf中的選項log-queries-not-using-indexes用於控制它。 從my.cnf的此代碼段可以看到,我的(已關閉)已關閉


mysql> show variables like 'log_queries_not_using_indexes';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF   |
+-------------------------------+-------+
1 row in set (0.00 sec)


如果您無權訪問my.cnf,則可以使用SQL檢查


 mysql> show variables like 'log_queries_not_using_indexes'; +-------------------------------+-------+ | Variable_name | Value | +-------------------------------+-------+ | log_queries_not_using_indexes | OFF | +-------------------------------+-------+ 1 row in set (0.00 sec) 



希望有幫助!

克里斯

檢查變量log-queries-not-using-indexes

show variables like '%log_queries_not_using_indexes%';
+-------------------------------+-------+
| Variable_name                 | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF   | 
+-------------------------------+-------+

對於您的情況,必須將其設置為OFF,如果為ON,則可以在my.cnf文件中設置log_queries_not_using_indexes = OFF ,然后重新啟動MySQL服務器。

AFAIK MySQL測量從提交查詢到獲取階段結束之間的數據獲取查詢的查詢時間。

Start timer
Start fast SELECT query
Wait for result 
Check timer and note time
sleep 2 seconds
fetch query results
Stop timer

將以記下的noted time<2send time>2s ,並且緩慢的查詢日志在較長的時間上觸發。

手冊中 ,您需要檢查與將查詢寫入show query日志相關的其他配置。

服務器按以下順序使用控制參數來確定是否將查詢寫入慢查詢日志:

1.查詢必須不是管理語句,或者必須指定--log-slow-admin-statements。

2.查詢必須至少花費long_query_time秒,或者必須啟用log_queries_not_using_indexes,並且查詢不使用任何索引進行行查找。

3.查詢必須至少檢查了min_examined_row_limit行。

4.不得根據log_throttle_queries_not_using_indexes設置禁止查詢。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM