时间:2021-07-01 10:21:17 帮助过:15人阅读
#查询记录最多的20个sql语句,并写到select.log中去 mysqlsla -lt slow --sort t_sum --top 20 /data/mysql/127-slow.log >/tmp/select.log #统计慢查询文件为/data/mysql/127-slow.log的所有select的慢查询sql,并显示执行时间最长的100条sql,并写到sql_select.log中去 mysqlsla -lt slow -sf "+select" -top 100 /data/mysql/127-slow.log >/tmp/sql_select.log #统计慢查询文件为/data/mysql/127-slow.log的数据库为mydata的所有select和update的慢查询sql,并查询次数最多的100条sql,并写到sql_num.sql中去 mysqlsla -lt slow -sf "+select,update" -top 100 -sort c_sum -db mydata /data/mysql/127-slow.log >/tmp/sql_num.log
比如说,原始慢日志中有一堆的下列语句:
# Time: 110417 0:00:09
# User@Host: junsansi[junsansi] @ [192.168.1.27]
# Query_time: 3 Lock_time: 0 Rows_sent: 1 Rows_examined: 17600
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW1MICAN2‘;
# User@Host: junsansi[junsansi] @ [192.168.1.27]
# Query_time: 4 Lock_time: 0 Rows_sent: 1 Rows_examined: 17600
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW2MICAN2‘;
# User@Host: jss[junsansi] @ [192.168.1.26]
# Query_time: 4 Lock_time: 0 Rows_sent: 1 Rows_examined: 17600
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW3MICAN2‘;
# User@Host: junsansi[junsansi] @ [192.168.1.27]
# Query_time: 3 Lock_time: 0 Rows_sent: 1 Rows_examined: 17600
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW4MICAN2‘;
# User@Host: jss[junsansi] @ [192.168.1.26]
# Query_time: 5 Lock_time: 0 Rows_sent: 1 Rows_examined: 17600
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW5MICAN2‘;
....................
....................
直接阅读的操作体验很不好,使用mysqlsla处理后,结果呈现如下:
Count : 23 (8.52%)
Time : 102 s total, 4.434783 s avg, 3 s to 7 s max (6.79%)
95% of Time : 88 s total, 4.190476 s avg, 3 s to 6 s max
Lock Time (s) : 0 total, 0 avg, 0 to 0 max (0.00%)
95% of Lock : 0 total, 0 avg, 0 to 0 max
Rows sent : 1 avg, 1 to 1 max (0.02%)
Rows examined : 11.53k avg, 5.70k to 17.60k max (1.07%)
Database : jssdb
Users :
junsansi@ 192.168.1.27 : 86.96% (20) of query, 11.11% (30) of all users
jss@ 192.168.1.26 : 13.04% (3) of query, 2.96% (8) of all users
Query abstract:
SELECT MIN(doc_his_id) AS doc_his_id FROM t_******** WHERE doc_his_isteammate=N AND doc_his_editor_user_id_encrypt=‘S‘;
Query sample:
select min(DOC_HIS_ID) AS DOC_HIS_ID from t_******** where DOC_HIS_ISTEAMMATE=1 and DOC_HIS_EDITOR_USER_ID_ENCRYPT=‘nfEACAwQEW2MICAN2‘;
在上述结果中,语句的执行情况(执行次数,对象信息,查询记录量,时间开销,来源统计)等信息一目了然,比较便于DBA进一步分析了。
原文:http://blog.itpub.net/7607759/viewspace-692828/
mysql慢查询日志分析工具 mysqlsla(转)
标签:阅读 慢日志 mon 进制 第三方 linux div 完全 sql数据库