1、問題
當然又被度娘(我冤枉)坑了噻,網友說配置文件寫下面三行:
log-slow-queries=D:\Program Files\mysql-5.7.11-winx64\data\low.log
long_query_time=2 (記錄超過的時間,默認為10s) log-queries-not-using-indexes (log下來沒有使用索引的query,可以根據情況決定是否開啟)
俺信了噻,就去my.ini中加入了這三行配置,net start mysql,啟動不了了,查看錯誤日志:
[ERROR] unknown variable 'log-slow-queries=D:\Program Files\mysql-5.7.11-winx64\data\low.log'
2、解決方法
無奈之下,只好去mysql官方網站去查去了,頭疼,不喜歡看英文啊,沒中文好看,中文多漂亮啊,要姿勢有姿勢,要內涵有內涵。
http://www.mysql.com,進入documentation tab頁,點那個叫[Reference Manual]的大按鈕,還算漂亮;
懵逼了吧,這怎么找啊?
當然最快的是搜索slow query,mysql官網有這功能,一定比度娘准確,然后會出一堆slow query的連接,選一個對應的版本就可以;
不過,俺比較懶,俺喜歡猜過去,第一猜,如果咱是手冊編寫人員,會把這個慢查詢放哪啊?肯定有個配置管理的章節吧
很湊巧,右側樹列表有個MySQL server Administration,點開它
一眼就發現了MySQL server logs,繼續點開,一定會有一個叫做slow query log的鏈接,點開它。掃了掃,找到這兩段話
If you specify no name for the slow query log file, the default name is
. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.host_name
-slow.log
如果你設置慢查詢日志文件名,默認會在data目錄下創建一個host_name-slow.log的文件;
To disable or enable the slow query log or change the log file name at runtime, use the global slow_query_log
and slow_query_log_file
system variables. Set slow_query_log
to 0 (or OFF
) to disable the log or to 1 (or ON
) to enable it. Set slow_query_log_file
to specify the name of the log file. If a log file already is open, it is closed and the new file is opened.
為了使慢查詢生效,需要設置slow_query_log=1或者on,否則設置為0或off。設置slow_query_log_file指定日志文件名
看清楚了,不是log-slow-queries,看來這個是老版本的mysql配置寫法,5.7是用slow_query_log_file,如果是我,我也改成這個變量名,什么叫
log-slow-queries,完全沒有slow_query_log_file語義明確。