pt-query-digest分析mysql查詢日誌
[root@hank-yoon log]# pt-query-digest slowq.log
# 200ms user time, 10ms system time, 24.39M rss, 205.12M vsz
# Current date: Thu Dec 17 15:32:04 2015
# Hostname: hank-yoon.com
# Files: slowq.log
# Overall: 8 total, 2 unique, 0.00 QPS, 0.00x concurrency ________________
# Time range: 2015-12-17 05:00:09 to 15:30:01
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 15s 1s 7s 2s 7s 2s 1s
# Lock time 1ms 85us 251us 175us 247us 49us 194us
# Rows sent 213.24k 4 213.21k 26.65k 211.82k 70.05k 3.89
# Rows examine 2.40M 213.21k 320.55k 306.93k 312.96k 33.45k 312.96k
# Rows affecte 0 0 0 0 0 0 0
# Bytes sent 19.42M 1.44k 19.41M 2.43M 19.33M 6.39M 1.39k
# Query size 6.46k 768 836 827.50 833.10 25.62 833.10
1、Overall: 8 total 總共查詢8條
2、2 unique: 唯一查詢數量,對查詢條件過濾後,總共有多少個不同的查詢,一共有2個
3、Time range: 2015-12-17 05:00:09 to 15:30:01 時間範圍,從幾點開始到幾點的查詢
4、total:總計 min:最小 max:最大 avg:平均 95%:將所有值從小到大排列,位於95%的那個數
stddev:標準偏差 median:中位數,位置位於中間那個數
5、Exec time:執行時間
6、Lock time:鎖時間
7、Rows sent:最後返回給客戶端的行數,查詢大小
8、Rows affecte:傳送改變的行數
9、Rows examine:執行器需要檢查的行數大小
10、Query size:查詢語句的字元數
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============= ===== ====== ===== ===============
# 1 0x50EF20421A671146 7.4117 50.7% 7 1.0588 0.00 SELECT erp_order erp_order_option wms_order_sync jx_region
# 2 0x9B9DD48242D6C02D 7.2176 49.3% 1 7.2176 0.00 SELECT jx_erp_goods_ware
1、Rank:整個分析中語句排名,效能最差的
2、Response time:語句響應時間及整體佔比情況
3、Calls:執行次數
4、R/Call:每次執行的平均響應時間
5、V/M:響應時間的差異平均對比率
# Query 1: 0.00 QPS, --QPS:每秒查詢數
0.00x concurrency, --concurrency:該查詢的近似併發值
ID 0x50EF20421A671146 --16進位制查詢的指紋,去掉了多餘的空格和文字字元,轉換成小寫,使用--filter可以進行過濾
at byte 5592 --查詢語句在日誌檔案中的偏移量,不一定精確,根據偏移量在日誌檔案中查詢tail -c +5592 slowq.log |head
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2015-12-17 05:24:01 to 15:30:01
# Attribute pct total min max avg 95% stddev median
--PCT:指的是執行語句佔概要報告中的百分比,佔有87%,一共執行了7次
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 87 7
# Exec time 50 7s 1s 1s 1s 1s 35ms 1s
# Lock time 93 1ms 142us 251us 188us 247us 38us 185us
# Rows sent 0 28 4 4 4 4 0 4
# Rows examine 91 2.19M 320.15k 320.55k 320.32k 312.96k 0 312.96k
# Rows affecte 0 0 0 0 0 0 0 0
# Bytes sent 0 10.10k 1.44k 1.44k 1.44k 1.44k 0 1.44k
# Query size 88 5.71k 836 836 836 836 0 836
# String:
# Databases yoon --資料庫名
# Hosts
# Last errno 0
# Users zhu_yoon --執行語句使用者
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s ################################################################
# 10s+
# Tables
# SHOW TABLE STATUS FROM `yoon` LIKE 'erp_order'\G
# SHOW CREATE TABLE `yoon`.`erp_order`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'erp_order_option'\G
# SHOW CREATE TABLE `yoon`.`erp_order_option`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'wms_order_sync'\G
# SHOW CREATE TABLE `yoon`.`wms_order_sync`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'jx_region'\G
# SHOW CREATE TABLE `yoon`.`jx_region`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT eo.pay_status,(CASE WHEN eo.order_amount >0 THEN (eo.order_amount- eo.platform_discount) ELSE eo.order_amount END) codValue,eo.invoice_no,eo.consignee realName,eo.tel phone,eo.mobile,eo.zipcode postCode,eoo.auto_weight totalWeight,eoo.packages totalNumber,
jrp.region_name province,jrc.region_name city,IFNULL(jrd.region_name,eo.district_name) county,eo.address address,eo.order_id OrderId
FROM erp_order eo
JOIN erp_order_option eoo ON eo.order_id=eoo.order_id
JOIN wms_order_sync wos ON wos.OrderId=eo.order_id
LEFT JOIN jx_region jrp ON jrp.region_id=eo.province_id
LEFT JOIN jx_region jrc ON jrc.region_id=eo.city_id
LEFT JOIN jx_region jrd ON jrd.region_id=eo.district_id WHERE wos.IsValid=0 AND wos.DealFlag=0
and eo.ware_id=5
AND eo.shipping_id=93
GROUP BY eo.order_id ORDER BY eoo.sendtime DESC LIMIT 20\G
(1)直接分析慢查詢檔案:
pt-query-digest slowq.log > slow_report.log
(2)分析最近12小時內的查詢:
pt-query-digest --since=12h slowq.log > slow_report.log
(3)分析指定時間範圍內的查詢:
pt-query-digest slowq.log --since '2015-04-17 09:30:00' --until '2015-04-17 10:00:00'> > slow_report.log
(4)分析指含有select語句的慢查詢
pt-query-digest--filter '$event->{fingerprint} =~ m/^select/i' slowq.log> slow_report.log
(5) 針對某個使用者的慢查詢
pt-query-digest--filter '($event->{user} || "") =~ m/^root/i' slowq.log> slow_report.log
(6) 查詢所有所有的全表掃描或full join的慢查詢
pt-query-digest--filter '(($event->{Full_scan} || "") eq "yes") ||(($event->{Full_join} || "") eq "yes")' slowq.log > slow_report.log
(7)把查詢儲存到query_review表
pt-query-digest --user=root --password=abc123 --review h=localhost,D=test,t=query_review--create-review-table slowq.log
(8)把查詢儲存到query_history表
pt-query-digest --user=root --password=abc123 --review h=localhost,D=test,t=query_ history--create-review-table slowq.log
pt-query-digest --user=root --password=abc123--review h=localhost,D=test,t=query_history--create-review-table slowq.log
(9)透過tcpdump抓取mysql的tcp協議資料,然後再分析
tcpdump -s 65535 -x -nn -q -tttt -i any -c 1000 port 3306 > mysql.txt
pt-query-digest --type tcpdump mysql.txt> slow_report.log
(10)分析binlog
mysqlbinlog mysql-bin.000077 > mysql-bin000077.sql
pt-query-digest --type=binlog mysql-bin000077.sql > slow_report.log
(11)分析general log
pt-query-digest --type=genlog localhost.log > slow_report.log
# 200ms user time, 10ms system time, 24.39M rss, 205.12M vsz
# Current date: Thu Dec 17 15:32:04 2015
# Hostname: hank-yoon.com
# Files: slowq.log
# Overall: 8 total, 2 unique, 0.00 QPS, 0.00x concurrency ________________
# Time range: 2015-12-17 05:00:09 to 15:30:01
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 15s 1s 7s 2s 7s 2s 1s
# Lock time 1ms 85us 251us 175us 247us 49us 194us
# Rows sent 213.24k 4 213.21k 26.65k 211.82k 70.05k 3.89
# Rows examine 2.40M 213.21k 320.55k 306.93k 312.96k 33.45k 312.96k
# Rows affecte 0 0 0 0 0 0 0
# Bytes sent 19.42M 1.44k 19.41M 2.43M 19.33M 6.39M 1.39k
# Query size 6.46k 768 836 827.50 833.10 25.62 833.10
1、Overall: 8 total 總共查詢8條
2、2 unique: 唯一查詢數量,對查詢條件過濾後,總共有多少個不同的查詢,一共有2個
3、Time range: 2015-12-17 05:00:09 to 15:30:01 時間範圍,從幾點開始到幾點的查詢
4、total:總計 min:最小 max:最大 avg:平均 95%:將所有值從小到大排列,位於95%的那個數
stddev:標準偏差 median:中位數,位置位於中間那個數
5、Exec time:執行時間
6、Lock time:鎖時間
7、Rows sent:最後返回給客戶端的行數,查詢大小
8、Rows affecte:傳送改變的行數
9、Rows examine:執行器需要檢查的行數大小
10、Query size:查詢語句的字元數
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============= ===== ====== ===== ===============
# 1 0x50EF20421A671146 7.4117 50.7% 7 1.0588 0.00 SELECT erp_order erp_order_option wms_order_sync jx_region
# 2 0x9B9DD48242D6C02D 7.2176 49.3% 1 7.2176 0.00 SELECT jx_erp_goods_ware
1、Rank:整個分析中語句排名,效能最差的
2、Response time:語句響應時間及整體佔比情況
3、Calls:執行次數
4、R/Call:每次執行的平均響應時間
5、V/M:響應時間的差異平均對比率
# Query 1: 0.00 QPS, --QPS:每秒查詢數
0.00x concurrency, --concurrency:該查詢的近似併發值
ID 0x50EF20421A671146 --16進位制查詢的指紋,去掉了多餘的空格和文字字元,轉換成小寫,使用--filter可以進行過濾
at byte 5592 --查詢語句在日誌檔案中的偏移量,不一定精確,根據偏移量在日誌檔案中查詢tail -c +5592 slowq.log |head
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: 2015-12-17 05:24:01 to 15:30:01
# Attribute pct total min max avg 95% stddev median
--PCT:指的是執行語句佔概要報告中的百分比,佔有87%,一共執行了7次
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 87 7
# Exec time 50 7s 1s 1s 1s 1s 35ms 1s
# Lock time 93 1ms 142us 251us 188us 247us 38us 185us
# Rows sent 0 28 4 4 4 4 0 4
# Rows examine 91 2.19M 320.15k 320.55k 320.32k 312.96k 0 312.96k
# Rows affecte 0 0 0 0 0 0 0 0
# Bytes sent 0 10.10k 1.44k 1.44k 1.44k 1.44k 0 1.44k
# Query size 88 5.71k 836 836 836 836 0 836
# String:
# Databases yoon --資料庫名
# Hosts
# Last errno 0
# Users zhu_yoon --執行語句使用者
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s ################################################################
# 10s+
# Tables
# SHOW TABLE STATUS FROM `yoon` LIKE 'erp_order'\G
# SHOW CREATE TABLE `yoon`.`erp_order`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'erp_order_option'\G
# SHOW CREATE TABLE `yoon`.`erp_order_option`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'wms_order_sync'\G
# SHOW CREATE TABLE `yoon`.`wms_order_sync`\G
# SHOW TABLE STATUS FROM `yoon` LIKE 'jx_region'\G
# SHOW CREATE TABLE `yoon`.`jx_region`\G
# EXPLAIN /*!50100 PARTITIONS*/
SELECT eo.pay_status,(CASE WHEN eo.order_amount >0 THEN (eo.order_amount- eo.platform_discount) ELSE eo.order_amount END) codValue,eo.invoice_no,eo.consignee realName,eo.tel phone,eo.mobile,eo.zipcode postCode,eoo.auto_weight totalWeight,eoo.packages totalNumber,
jrp.region_name province,jrc.region_name city,IFNULL(jrd.region_name,eo.district_name) county,eo.address address,eo.order_id OrderId
FROM erp_order eo
JOIN erp_order_option eoo ON eo.order_id=eoo.order_id
JOIN wms_order_sync wos ON wos.OrderId=eo.order_id
LEFT JOIN jx_region jrp ON jrp.region_id=eo.province_id
LEFT JOIN jx_region jrc ON jrc.region_id=eo.city_id
LEFT JOIN jx_region jrd ON jrd.region_id=eo.district_id WHERE wos.IsValid=0 AND wos.DealFlag=0
and eo.ware_id=5
AND eo.shipping_id=93
GROUP BY eo.order_id ORDER BY eoo.sendtime DESC LIMIT 20\G
(1)直接分析慢查詢檔案:
pt-query-digest slowq.log > slow_report.log
(2)分析最近12小時內的查詢:
pt-query-digest --since=12h slowq.log > slow_report.log
(3)分析指定時間範圍內的查詢:
pt-query-digest slowq.log --since '2015-04-17 09:30:00' --until '2015-04-17 10:00:00'> > slow_report.log
(4)分析指含有select語句的慢查詢
pt-query-digest--filter '$event->{fingerprint} =~ m/^select/i' slowq.log> slow_report.log
(5) 針對某個使用者的慢查詢
pt-query-digest--filter '($event->{user} || "") =~ m/^root/i' slowq.log> slow_report.log
(6) 查詢所有所有的全表掃描或full join的慢查詢
pt-query-digest--filter '(($event->{Full_scan} || "") eq "yes") ||(($event->{Full_join} || "") eq "yes")' slowq.log > slow_report.log
(7)把查詢儲存到query_review表
pt-query-digest --user=root --password=abc123 --review h=localhost,D=test,t=query_review--create-review-table slowq.log
(8)把查詢儲存到query_history表
pt-query-digest --user=root --password=abc123 --review h=localhost,D=test,t=query_ history--create-review-table slowq.log
pt-query-digest --user=root --password=abc123--review h=localhost,D=test,t=query_history--create-review-table slowq.log
(9)透過tcpdump抓取mysql的tcp協議資料,然後再分析
tcpdump -s 65535 -x -nn -q -tttt -i any -c 1000 port 3306 > mysql.txt
pt-query-digest --type tcpdump mysql.txt> slow_report.log
(10)分析binlog
mysqlbinlog mysql-bin.000077 > mysql-bin000077.sql
pt-query-digest --type=binlog mysql-bin000077.sql > slow_report.log
(11)分析general log
pt-query-digest --type=genlog localhost.log > slow_report.log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-1874419/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 關於MySQL 通用查詢日誌和慢查詢日誌分析MySql
- mysql慢查詢和錯誤日誌分析MySql
- MySQL:慢查詢日誌MySql
- MySQL 通用查詢日誌MySql
- MySQL 慢查詢分析工具~pt-query-digest 詳解MySql
- 對 MySQL 慢查詢日誌的簡單分析MySql
- 慢查詢日誌開啟分析
- mysql之 slow log 慢查詢日誌MySql
- MySQL Slow Query log(慢查詢日誌)MySql
- Mysql慢查詢日誌檔案轉ExcelMySqlExcel
- MySQL慢查詢日誌相關設定MySql
- 如何在MySQL中開啟慢查詢日誌?MySql
- 資料庫MySQL一般查詢日誌或者慢查詢日誌歷史資料的清理資料庫MySql
- 日誌查詢錯誤
- linux查詢日誌技巧Linux
- loki的日誌查詢Loki
- 【趙渝強老師】MySQL的慢查詢日誌MySql
- MySQL中用通用查詢日誌找出查詢次數最多的語句的教程MySql
- 如何精準查詢日誌
- Linux 查詢 日誌 相關命令Linux
- Logtail:像查詢資料庫一樣查詢日誌AI資料庫
- 分析“蜜罐NS”上的查詢,提升DNS日誌的質量DNS
- MySQL查詢擷取分析MySql
- Mysql 慢日誌分析工具MysqldumpslowMySql
- Redis慢查詢日誌學習功能Redis
- 網站伺服器被入侵後的日誌查詢與分析網站伺服器
- 日誌分析-apache日誌分析Apache
- Centos系統關閉Mysql資料庫查詢操作日誌的方法CentOSMySql資料庫
- MySQL 查詢效能分析之 ExplainMySqlAI
- 【mysql】explain命令分析慢查詢MySqlAI
- ITMySQL錯誤日誌與通用查詢日誌圖文詳析jugMySql
- zabbix agent 日誌檔案輪詢分析
- Kibana+Logstash+Elasticsearch 日誌查詢系統Elasticsearch
- 筆記 mongo查詢慢日誌,建立索引筆記Go索引
- [爬坑日誌1]寫查詢的mysql一些小注意事項MySql
- MySQL慢查詢分析工具之mysqldumpslowMySql
- 如何啟用Hibernate慢查詢日誌? -Vlad Mihalcea
- [日誌分析篇]-利用ELK分析jumpserver日誌-日誌拆分篇Server
- Mysql日誌MySql