mysqlsl是一个mysql日志分析工具了,下面本文章来给大家介绍mysqlsla工具安装也mysqlsla工具对mysql日志分析详解,有需要了解的朋友可参考一下.
1.安装mysqlsla,代码如下:
- wget http:
- tar zvxf mysqlsla-2.03.tar.gz
- cd mysqlsla-2.03
- perl Makefile.PL
- make
- make install
perl Makefile.PL会报错,根据出错内容百度下都有相关信息,无非yum install一些东西.
2.使用mysqlsla语法,代码如下:
- Slow log: mysqlsla -lt slow slow.log
- General log: mysqlsla -lt general general.log
- Binary log: mysqlbinlog bin.log | mysqlsla -lt binary -
3.分析日志,代码如下:
./bin/mysqlsla ../slowlog/10.4.1.107.log.1206
分析结果:
- Auto-detected logs as slow logs
- Report for slow logs: ../slowlog/10.4.1.107.log.1206
- 799 queries total, 4 unique
- Sorted by 't_sum'
- Grand Totals: Time 1.25k s, Lock 0 s, Rows sent 917, Rows Examined 426.83M
-
- ______________________________________________________________________ 001 ___
- Count : 372 (46.56%)
- Time : 581.404365 s total, 1.562915 s avg, 1.001595 s to 4.129653 s max (46.56%)
- 95% of Time : 516.842801 s total, 1.464144 s avg, 1.001595 s to 2.815608 s max
- Lock Time (s) : 40.935 ms total, 110 ?s avg, 71 ?s to 211 ?s max (44.74%)
- 95% of Lock : 38.016 ms total, 108 ?s avg, 71 ?s to 135 ?s max
- Rows sent : 1 avg, 1 to 1 max (40.57%)
- Rows examined : 387.71k avg, 225.34k to 725.90k max (33.79%)
- Database : yy
- Users :
- yyr@ 10.4.1.83 : 33.87% (126) of query, 34.79% (278) of all users
- yyr@ 10.4.1.81 : 33.33% (124) of query, 32.79% (262) of all users
- yyr@ 10.4.1.82 : 32.80% (122) of query, 32.42% (259) of all users
-
- Query abstract:
- SET timestamp=N; SELECT COUNT(N) AS cnt FROM qz_feed WHERE (qz_id='S') AND (feed_key IN (S1)) AND (created>N) AND feed_id IN(SELECT from_id FROM qz_notice WHERE type_detail='S' AND member_id=N AND isnew=N);
-
- Query sample:
- SET timestamp=1354637384;
- SELECT COUNT(1) AS cnt FROM qz_feed WHERE (qz_id='377') AND (feed_key in ('speech_add')) AND (created>0) AND feed_id IN(SELECT from_id FROM qz_notice WHERE type_detail='speech_add' AND member_id=38011 AND isnew=1);
常用参数说明:
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条记录,代码如下:
mysqlsla -lt slow -sort c_sum_p -sf "+select" -db backup -top 2 /tmp/127_slow.log
分析后的效果:
- ______________________________________________________________________ 001 ___
- Count : 18 (75.00%)
- Time : 15 s total, 833.333 ms avg, 0 to 8 s max (93.75%)
- 95% of Time : 7 s total, 411.765 ms avg, 0 to 4 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 : 0 avg, 0 to 0 max (0.00%)
- Rows examined : 116.51k avg, 8 to 1.05M max (99.99%)
- Database :
- Users :
- root@localhost : 100.00% (18) of query, 100.00% (24) of all users
-
- Query abstract:
- INSERT INTO t2 SELECT * FROM t2;
-
- Query sample:
- insert into t2 select * from t2;
选项说明:总查询次数 (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可以会根据系统开销最大的查询(总查询时间)来排序,显示最大最小平均查询时间,这些都是很用的功能. |