2011-06-21 19 views
11

我正在使用MySQL服務器版本:5.5.8日誌MySQL社區服務器(GPL)
我想記錄查詢不使用INDEX,也是太慢!
我在這裏複製我的my.ini設置。日誌QUERIES不使用INDEX - MySQL

的[mysqld]
端口= 3306
日誌= 「E:/wamp/logs/genquery.log」

log_slow_queries
long_query_time時間= 1
slow_query_log = 1個
slow_query_log_file =「E: /wamp/logs/slowquery.log「

我需要做什麼改變?

回答

26

log_queries_not_using_indexes =1 //(or Yes)(從mysql

+7

這是個好主意嗎?因爲最終會得到GB的緩慢查詢日誌,因爲在不使用索引因爲沒有索引更快而不使用索引的情況下,將會記錄幾分之一秒的查詢 – wired00

+0

然而,這會記錄不使用索引的查詢,無論它們是否超過long_query_time。該問題詢問沒有索引且長時間運行的查詢。 – ClearCrescendo

+0

這將記錄不使用long_query_time val的索引regardeless的查詢嗎? –

5

log_queries_not_using_indexes

Command-Line Format --log-queries-not-using-indexes 
Option-File Format log-queries-not-using-indexes 
Option Sets Variable Yes, log_queries_not_using_indexes 
Variable Name log_queries_not_using_indexes 
Variable Scope Global 
Dynamic Variable Yes 
    Permitted Values 
Type boolean 

是否不使用索引的查詢記錄到慢查詢日誌。參見5.2.4節,

1

也許對Linux用戶有用。 (Testet:Ubuntu的16.04),在終端和編輯MySQL配置

獲得root

su 
vim /etc/mysql/conf.d/mysql.cnf 

[mysqld] 
slow_query_log=1 
slow_query_log_file=/var/log/mysql/slow-query.log 
long_query_time=1 
log_queries_not_using_indexes=1 

添加日誌文件,然後重新啓動MySQL服務器

touch /var/log/mysql/slow-query.log 
chown mysql:adm /var/log/mysql/slow-query.log 
chmod 640 slow-query.log 
service mysql restart 

與SQL測試慢日誌查詢

/* Activate query log - Maybe useful to show errors (not necessary) */ 
SET GLOBAL SLOW_QUERY_LOG=ON; 

/* Check if slow query log is working */ 
SELECT SLEEP(2);