一、安装
wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
tar xzvf mysqlsla-2.03.tar.gz
cd mysqlsla-2.03
perl Makefile.PL
make
make install
二、用法
mysqlsla /home/mysql/server06-slow.log
[root@server06 ~]# /usr/local/bin/mysqlsla /home/mysql/server06-slow.log
Auto-detected logs as slow logs
Report for slow logs: /home/mysql/server06-slow.log
16 queries total, 14 unique
Sorted by 't_sum'
Grand Totals: Time 3 s, Lock 0 s, Rows sent 305, Rows Examined 316
______________________________________________________________________ 001 ___
Count : 1 (6.25%)
Time : 1.028548 s total, 1.028548 s avg, 1.028548 s to 1.028548 s max (37.56%)
Lock Time (s) : 0 total, 0 avg, 0 to 0 max (0.00%)
Rows sent : 1 avg, 1 to 1 max (0.33%)
Rows examined : 0 avg, 0 to 0 max (0.00%)
Database :
Users :
root@localhost : 100.00% (1) of query, 43.75% (7) of all users
Query abstract:
SET timestamp=N; SELECT sleep(N);
Query sample:
SET timestamp=1336982382;
select sleep(1);
选项说明:
总查询次数 (queries total), 去重后的sql数量 (unique)
输出报表的内容排序(sorted by)
最重大的慢sql统计信息, 包括 平均执行时间, 等待锁时间, 结果行的总数, 扫描的行总数.
Count, sql的执行次数及占总的slow log数量的百分比.
Time, 执行时间, 包括总时间, 平均时间, 最小, 最大时间, 时间占到总慢sql时间的百分比.
95% of Time, 去除最快和最慢的sql, 覆盖率占95%的sql的执行时间.
Lock Time, 等待锁的时间.
95% of Lock , 95%的慢sql等待锁时间.
Rows sent, 结果行统计数量, 包括平均, 最小, 最大数量.
Rows examined, 扫描的行数量.
Database, 属于哪个数据库
Users, 哪个用户,IP, 占到所有用户执行的sql百分比
Query abstract, 抽象后的sql语句
Query sample, sql语句
mysqlsla常用参数说明:
1) -log-type (-lt) type logs:
通过这个参数来制定log的类型,主要有slow, general, binary, msl, udl,分析slow log时通过制定为slow.
2) -sort:
制定使用什么参数来对分析结果进行排序,默认是按照t_sum来进行排序。
t_sum:按总时间排序
c_sum:按总次数排序
c_sum_p: sql语句执行次数占总执行次数的百分比。
3) -top:
显示sql的数量,默认是10,表示按规则取排序的前多少条
4) –statement-filter (-sf) [+-][TYPE]:
过滤sql语句的类型,比如select、update、drop.
[TYPE]有SELECT, CREATE, DROP, UPDATE, INSERT,例如"+SELECT,INSERT",不出现的默认是-,即不包括。
5) db:要处理哪个库的日志:
例如,只取backup库的select语句、按c_sum_p排序的前2条记录
[root@server06 ~]# mysqlsla -lt slow -sort c_sum_p -sf "+select" -db backup -top 2 /home/mysql/server06-slow.log
Report for slow logs: /home/mysql/server06-slow.log
11 queries total, 9 unique
Sorted by 'c_sum_p'
Grand Totals: Time 2 s, Lock 0 s, Rows sent 261, Rows Examined 271
______________________________________________________________________ 001 ___
Count : 2 (18.18%)
Time : 293 otal, 146 vg, 128 o 165 ax (0.02%)
Lock Time (s) : 59 otal, 29 vg, 27 o 32 ax (0.16%)
Rows sent : 6 avg, 6 to 6 max (4.60%)
Rows examined : 6 avg, 6 to 6 max (4.43%)
Database :
Users :
root@localhost : 100.00% (2) of query, 54.55% (6) of all users
Query abstract:
SELECT * FROM supe_crons WHERE available>N;
Query sample:
SELECT * FROM supe_crons WHERE available>0;
______________________________________________________________________ 002 ___
Count : 2 (18.18%)
Time : 346 otal, 173 vg, 172 o 174 ax (0.02%)
Lock Time (s) : 84 otal, 42 vg, 34 o 50 ax (0.23%)
Rows sent : 1 avg, 1 to 1 max (0.77%)
Rows examined : 7 avg, 7 to 7 max (5.17%)
Database :
Users :
root@localhost : 100.00% (2) of query, 54.55% (6) of all users
Query abstract:
SELECT nextrun FROM supe_crons WHERE available>N AND nextrun>'S' ORDER BY nextrun LIMIT N;
Query sample:
SELECT nextrun FROM supe_crons WHERE available>0 AND nextrun>'1336982982' ORDER BY nextrun LIMIT 1;
[root@server06 ~]#
本文出自 “fairexchange” 博客,谢绝转载!