MySQL慢查詢日誌分析工具mysqldumpslow

來源:互聯網
上載者:User

MySQL慢查詢日誌分析工具mysqldumpslow

mysqldumpslow是mysql內建的一種慢查詢日誌分析工具,顧名思義,就是查詢那些出那些查詢慢的SQL語句,由此分析出SQL查詢效率慢的原因。

通常來說,mysqldumpslow分組查詢的結果是相似的,它在展示統計結果時,可以將數字和字串分別抽象成“N”和“S”。當然也可以用-a 和 -n選項可以用來修改這些抽象的行為。

mysqldumpslow查詢命令

mysqldumpslow [options] [log_file]

mysqldumpslow選擇性參數(options),如下:

-a : 不將數字抽象成N,字串抽象成S。

樣本:

mysql%mysqldumpslow /home/mysql/logs/slow_query.log
Reading mysql slow query log from /home/mysql/logs/slow_query.log

Count: 1  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), FAVDBA[FAVDBA]@[10.1.45.51]
  # Schema:  Last_errno: N  Killed: N
  # Query_time: N.N  Lock_time: N.N  Rows_sent: N  Rows_examined: N  Rows_affected: N
  # Bytes_sent: N
  SET timestamp=N;
  SELECT EVENT_NAME, EVENT_SCHEMA, EVENT_DEFINITION FROM INFORMATION_SCHEMA.EVENTS

mysql%mysqldumpslow -a /home/mysql/logs/slow_query.log

Reading mysql slow query log from /home/mysql/logs/slow_query.log

Count: 1  Time=0.00s (0s)  Lock=0.00s (0s)  Rows=0.0 (0), FAVDBA[FAVDBA]@[10.1.45.51]
  # Schema:  Last_errno: 0  Killed: 0
  # Query_time: 0.004095  Lock_time: 0.002907  Rows_sent: 0  Rows_examined: 0  Rows_affected: 0
  # Bytes_sent: 140
  SET timestamp=1451270206;
  SELECT EVENT_NAME, EVENT_SCHEMA, EVENT_DEFINITION FROM INFORMATION_SCHEMA.EVENTS
 

-n N : 將數字抽象顯示成至少指定的位元

本文永久更新連結地址:

相關文章

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.