mysql慢查詢配置(5.7)


剛裝了Windows版mysql,想開啟慢查詢日志。

修改D:\mysql-5.7.23-winx64下my.ini配置文件,添加:

[mysqld]
slow_query_log = on
slow_query_log_file = D:\mysql_logs\slow_query.log
long_query_time = 2

注:前面必須加[mysqld] 我這邊配置前加了[mysql]導致讀取報錯。

mysql: [ERROR] unknown variable 'slow_query_log=on'

參數詳解:
slow_query_log = on #開啟慢查詢日志(或設置1)
slow_query_log_file = filename #指定日志文件保存路徑,不指定的話默認在數據庫文件目錄下,名為hostname-slow.log
long_query_time = 2 #指定達到多少秒才算慢查詢

log_queries_not_using_indexes=on #記錄沒有使用索引的查詢語句。!可能導致日志文件激增,謹慎使用。配合log_throttle_queries_not_using_indexes 使用。 

log_throttle_queries_not_using_indexes #表示每分鍾允許記錄到slow log的且未使用索引的sql語句次數。配合long_queries_not_using_indexes開啟使用。

min_examined_row_limit = 1000 #查詢檢查返回少於該參數指定行的SQL不被記錄到慢查詢日志.需要開啟log_queries_not_using_indexes=on 。注意:1查詢結果數量是<不會被記錄,=會被記錄。2,這個參數開啟后,long_query_time 參數失效 。
log_slow_admin_statements #記錄ALTER TABLE等語句引發的慢查詢

log_slow_slave_statements #記錄從服務器產生的慢查詢

min_examined_row_limit=Num of Rows 類似於SELECT ... FROM TBL LIMIT N這樣的全表掃描的查詢,如果--log_queries_not_using_indexes被開啟的話,因為用不到索引將要報告為慢查詢,可以在配置文件中使用min_examined_row_limit=Num of Rows來設置,如果要檢查的行數大於等於這個量的查詢,才會被報告為慢查詢。

配置結束之后,需要重啟才會生效。

windows版:mysqld restart

linux:service mysqld restart

登陸數據庫查詢下環境
show variables like '%query%';
執行一個慢查詢語句
select sleep(3);
查看文件,看日志是否生成。

參考鏈接:https://blog.csdn.net/huoyuanshen/article/details/52699569

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM