mysqldumpslow 分析slow query日誌和explain分析mysql查詢結構

來源:互聯網
上載者:User

標籤:格式   說明   日誌資訊   oss   表達   index   ref   mysqld   方式   

mysqldumpslow的使用:
比如我們要查詢按時間返回前5條日誌資訊,格式如下:
mysqldumpslow -s t -t 5 /var/log/mysql/slowquery_20180303.log

參數說明:
-s:排序方式 按鎖的時間l、返回的記錄數r、查詢的時間t、記錄的次數c,倒序的話可以加r
-t:查詢前多少條記錄
-g:支援Regex,以及忽略大小寫

順便說下explain
explain用來分析mysql查詢結構的主要關注四個參數值:
type、key、rows、extras
訪問類型 type: al最差,ref,eq_ref置中,null最好

all->index->range->ref->eq_ref->const或system->null

有無使用索引 key :key為空白沒有使用索引
找到所需記錄要讀取的行數:rows,rows值越小越好
extras:在什麼方式下找到了所需記錄,出現using filesort或using temporary表明效率低下,only index用到了索引,where used用到了where 過濾條件,impossible where 沒用到索引

mysqldumpslow 分析slow query日誌和explain分析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.