mysql最佳化 慢查詢(一)

來源:互聯網
上載者:User

標籤:

1.顯示慢查詢的一些參數的命令:show variables like ‘%slow%‘;結果

2.上面四個參數的意思是:

  log_slow_queries  off    表示“慢查詢”是“關閉的狀態”

  slow_launch_time  2     表示“查詢時間超過2秒就記錄到慢查詢日誌中”;

  slow_queries_log  off   表示慢查詢日誌開關是關著的

  slow_query_log_file "路徑"   表示慢查詢日誌存放完整路徑

3.開啟慢查詢的功能

    使用命令:set global log_slow_queries=on;   這樣就開啟了慢查詢的功能,此參數開啟了,slow_query_log就自動變成了on,關閉了的話也跟著關閉。

   

4. 其實slow_launch_time的設定跟慢查詢日誌的查詢閥值設定不同,表示了thread create的一個閥值,

     如果thread create的時間超過了這個值,這變數slow_launch_time的值加1.

  set global log_launch_time=1  這裡的時間值必須是整數,否則的話就話執行出錯

    慢查詢的查詢閥值是long_query_time 預設是10秒

5.設定slow_query_log_file的值是字串必須用引號引起來。

 

要真正修改慢查詢得去修改mysql的檔案,內容添加如下

long_query_time=0  只要是執行的都寫入了慢查詢日誌
log_slow_queries=on   慢查詢開關
slow_query_log =on    慢查詢日誌開關
slow_query_log_file="D:/phpStudy/1.log"  慢查詢記錄檔

 

並且還得重新啟動mysql才會生效

 

 慢查詢的日誌結構如下:

MySQLa, Version: 5.5.40-log (MySQL Community Server (GPL)). started with:TCP Port: 3306, Named Pipe: (null)Time                 Id Command    Argument# Time: 150705 18:31:54# [email protected]: root[root] @ localhost [127.0.0.1]# Query_time: 0.012001  Lock_time: 0.001000 Rows_sent: 51  Rows_examined: 51use weixin;SET timestamp=1436092314;show databases;# Time: 150705 18:32:55# [email protected]: root[root] @ localhost [127.0.0.1]# Query_time: 0.002000  Lock_time: 0.001000 Rows_sent: 1  Rows_examined: 1SET timestamp=1436092375;show variables like  "%query_time%";# Time: 150705 18:33:03# [email protected]: root[root] @ localhost [127.0.0.1]# Query_time: 0.001000  Lock_time: 0.000000 Rows_sent: 0  Rows_examined: 0use chlitina;SET timestamp=1436092383;use `chlitina`;# [email protected]: root[root] @ localhost [127.0.0.1]# Query_time: 0.031001  Lock_time: 0.001000 Rows_sent: 869  Rows_examined: 869SET timestamp=1436092383;select * from wp_consultant;# Time: 150705 18:33:40# [email protected]: root[root] @ localhost [127.0.0.1]# Query_time: 0.052003  Lock_time: 0.001000 Rows_sent: 869  Rows_examined: 1738SET timestamp=1436092420;select * from wp_consultant order by id desc;

 

    

mysql最佳化 慢查詢(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.