(转) mysqldumpslow使用说明总结
原文:http://blog.csdn.net/langkeziju/article/details/49301993
mysqldumpslow使用說(shuō)明
mysqldumpslow --help
Usage: mysqldumpslow [ OPTS... ] [ LOGS... ]
Parse and summarize the MySQL slow query log. Options are
??--verbose????verbose
??--debug??????debug
??--help???????write this text to standard output
??-v???????????verbose
??-d???????????debug
??-s ORDER?????what to sort by (al, at, ar, c, l, r, t), 'at' is default
????????????????al: average lock time
????????????????ar: average rows sent
????????????????at: average query time
?????????????????c: count
?????????????????l: lock time
?????????????????r: rows sent
?????????????????t: query time?
??-r???????????reverse the sort order (largest last instead of first)
??-t NUM???????just show the top n queries
??-a???????????don't abstract all numbers to N and strings to 'S'
??-n NUM???????abstract numbers with at least n digits within names
??-g PATTERN???grep: only consider stmts that include this string
??-h HOSTNAME??hostname of db server for *-slow.log filename (can be wildcard),
???????????????default is '*', i.e. match all
??-i NAME??????name of server instance (if using mysql.server startup script)
??-l???????????don't subtract lock time from total time
經(jīng)常使用幾個(gè)命令
-s ORDER what to sort by (t, at, l, al, r, ar etc), ‘a(chǎn)t’ is default
-t NUM just show the top n queries
-g PATTERN grep: only consider stmts that include this string
-s,是order的順序,說(shuō)明寫(xiě)的不夠詳細(xì),俺用下來(lái),包括看了代碼,主要有
c,t,l,r和ac,at,al,ar,分別是按照query次數(shù),查詢(xún)時(shí)間,lock的時(shí)間和返回的記錄數(shù)來(lái)排序,前面加了a的平均數(shù)
-t,是top n的意思,即為返回前面多少條的數(shù)據(jù)
-g,后邊可以寫(xiě)一個(gè)正則匹配模式,大小寫(xiě)不敏感的
例子
mysqldumpslow -t 10 -s t -g “l(fā)eft join” host-slow.log
使用mysqldumpslow的分析結(jié)果不會(huì)顯示具體完整的sql語(yǔ)句,
說(shuō)明:
1:假如真正的sql語(yǔ)句如下:SELECT * FROM sms_send WHERE service_id=10 GROUP BY content LIMIT 0, 1000;
mysqldumpslow顯示的結(jié)果會(huì)是:
Count: 1??Time=1.91s (1s)??Lock=0.00s (0s)??Rows=1000.0 (1000), vgos_dba[vgos_dba]@[10.130.229.196]
SELECT * FROM sms_send WHERE service_id=N GROUP BY content LIMIT N, N;
2:如果我們?cè)賵?zhí)行一條SELECT * FROM sms_send WHERE service_id=20 GROUP BY content LIMIT 10000, 1000;
mysqldumpslow顯示的結(jié)果會(huì)是:
Count: 2??Time=2.79s (5s)??Lock=0.00s (0s)??Rows=1.0 (2), vgos_dba[vgos_dba]@[10.130.229.196]
SELECT * FROM sms_send WHERE service_id=N GROUP BY content LIMIT N, N;
雖然這兩條語(yǔ)句條件不一樣,
1:一個(gè)是server_id=10,一個(gè)是server_id=20
2:一個(gè)是LIMIT 0, 1000,一個(gè)是LIMIT 10000, 1000
但是mysqldumpslow分析會(huì)認(rèn)為這是一種類(lèi)型的語(yǔ)句,會(huì)合并顯示。
3:假設(shè)我們執(zhí)行SELECT * FROM sms_send WHERE service_id<=10 GROUP BY content LIMIT 0, 1000;
執(zhí)行mysqldumpslow結(jié)果是
Count: 1??Time=2.91s (2s)??Lock=0.00s (0s)??Rows=1000.0 (1000), vgos_dba[vgos_dba]@[10.130.229.196]
SELECT * FROM sms_send WHERE service_id<=N GROUP BY content LIMIT N, N;
可以看出它和上面我們寫(xiě)的sql語(yǔ)句是兩種類(lèi)型
mysqldumpslow的分析結(jié)果
Count會(huì)告訴我們這種類(lèi)型的語(yǔ)句執(zhí)行了幾次,Time會(huì)告訴我們這種類(lèi)型的語(yǔ)句執(zhí)行的最大時(shí)間,Time=2.79s (5s)中(5s)
是指這類(lèi)型的語(yǔ)句執(zhí)行總共花費(fèi)的時(shí)間
Count: 2??Time=2.79s (5s)??Lock=0.00s (0s)??Rows=1.0 (2), vgos_dba[vgos_dba]@[10.130.229.196]
告訴我們執(zhí)行了2次,最大時(shí)間是2.79s,總共花費(fèi)時(shí)間5s,lock時(shí)間0s,單次返回的結(jié)果數(shù)是1條記錄,2次總共返回2條記錄m
mysqldumpslow -s t -t 10 slow.log
查詢(xún)的結(jié)果是10條執(zhí)行時(shí)間最慢的sql語(yǔ)句,其中-s t是指此類(lèi)類(lèi)型的語(yǔ)句的執(zhí)行總時(shí)長(zhǎng)
Count: 1??Time=2.91s (2s)??Lock=0.00s (0s)??Rows=1000.0 (1000), vgos_dba[vgos_dba]@[10.130.229.196]
和
Count: 2??Time=2.79s (5s)??Lock=0.00s (0s)??Rows=1.0 (2), vgos_dba[vgos_dba]@[10.130.229.196]
比較的結(jié)果是
Count: 2??Time=2.79s (5s)??Lock=0.00s (0s)??Rows=1.0 (2), vgos_dba[vgos_dba]@[10.130.229.196]排在前面,
以為比較的時(shí)長(zhǎng)是(5s)和(2s),而不是2.79s和2.91s
-s at比較的也是(5s)/count:2和(2s)/Count: 1
所以:-s at是Count: 1??Time=2.91s (2s)??Lock=0.00s (0s)??Rows=1000.0 (1000), vgos_dba[vgos_dba]@[10.130.229.196]排在前面。
?Rows=1.0 (2) 是按照以下邏輯展示的
(2)是指在Count: 2次數(shù)總共返回了2條記錄集;row=1.0顯示(2)/Count: 2,如果此時(shí)Count是3,
那么row的計(jì)算方式是Rows=2/3,Rows=0.67
主要功能是, 統(tǒng)計(jì)不同慢sql的
出現(xiàn)次數(shù)(Count),
執(zhí)行最長(zhǎng)時(shí)間(Time),
累計(jì)總耗費(fèi)時(shí)間(Time),
等待鎖的時(shí)間(Lock),
發(fā)送給客戶(hù)端的行總數(shù)(Rows),
掃描的行總數(shù)(Rows)
轉(zhuǎn)載于:https://www.cnblogs.com/liujiacai/p/7602610.html
總結(jié)
以上是生活随笔為你收集整理的(转) mysqldumpslow使用说明总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 首次写文章,分享一些渗透、安全工具
- 下一篇: 深入理解计算机系统(2.6)------