如何做到抓取mysql慢日志的分析工作-mysqlsla

在针对慢日志的时候,我们可以去做一定量的分析,如果数量少的话,我们可以直接打开此文本进行相关执行时间过多的语句的分析工作,但是在生产上可能此文本达到几十M,到多个G的工作时,我们人为性的肉眼就无法做到定质定量的分析工作了,此时我们可以借助一些外来工具,来协助我们进行追踪我们想要的目标,这几天我看到一个不错的工具可以分析出相关的sql的之行数据,以及sql的执行频率等问题!在此分享给大家!有相同类似工具请大家留意共享之,分享感谢!

配置相关的工具下载包;如:

http://hackmysql.com/mysqlsla

或者直接wget下载也可以;

 wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz

然后就是解压和使用perl编译相关文件的步骤以下是相关测试的截图部分;

[root@Slave02 local]# ls
bin          include  mysqlsla-2.03.tar.gz  xtrabackup-1.6.2
cmake-2.8.5  lib      sbin                  xtrabackup-1.6.2.tar.gz
doc          libexec  share
etc          man      software
games        mysql    src
[root@Slave02 local]# tar -zxvf mysqlsla-2.03.tar.gz 
mysqlsla-2.03/
mysqlsla-2.03/Changes
mysqlsla-2.03/INSTALL
mysqlsla-2.03/README
mysqlsla-2.03/Makefile.PL
mysqlsla-2.03/bin/
mysqlsla-2.03/bin/mysqlsla
mysqlsla-2.03/META.yml
mysqlsla-2.03/lib/
mysqlsla-2.03/lib/mysqlsla.pm
mysqlsla-2.03/MANIFEST
[root@Slave02 local]# ll
total 48624
drwxr-xr-x  2 root  root      4096 Sep 14 16:31 bin
drwxr-xr-x 14 root  root      4096 Sep 14 16:31 cmake-2.8.5
drwxr-xr-x  3 root  root      4096 Sep 14 16:31 doc
drwxr-xr-x  2 root  root      4096 Jan 27  2010 etc
drwxr-xr-x  2 root  root      4096 Jan 27  2010 games
drwxr-xr-x  2 root  root      4096 Jan 27  2010 include
drwxr-xr-x  2 root  root      4096 Jan 27  2010 lib
drwxr-xr-x  2 root  root      4096 Jan 27  2010 libexec
drwxr-xr-x  3 root  root      4096 Sep 14 16:31 man
drwxr-xr-x 13 mysql mysql     4096 Dec 10 11:40 mysql
drwxr-xr-x  4  1000  1000     4096 Nov 11  2008 mysqlsla-2.03
-rw-r--r--  1 root  root     33674 Jan 23 09:47 mysqlsla-2.03.tar.gz
drwxr-xr-x  2 root  root      4096 Jan 27  2010 sbin
drwxr-xr-x  5 root  root      4096 Sep 14 16:31 share
drwxr-xr-x  2 root  root      4096 Jan 21 11:05 software
drwxr-xr-x  2 root  root      4096 Jan 27  2010 src
drwxr-xr-x  9 mysql mysql     4096 Jan 21 13:42 xtrabackup-1.6.2
-rw-r--r--  1 root  root  49558000 Jan 21 11:55 xtrabackup-1.6.2.tar.gz
[root@Slave02 local]# cd mysqlsla-2.03
[root@Slave02 mysqlsla-2.03]# ls
bin  Changes  INSTALL  lib  Makefile.PL  MANIFEST  META.yml  README
[root@Slave02 mysqlsla-2.03]# perl Makefile.PL 
Checking if your kit is complete...
Looks good
Writing Makefile for mysqlsla
[root@Slave02 mysqlsla-2.03]# make && make install;
cp lib/mysqlsla.pm blib/lib/mysqlsla.pm
cp bin/mysqlsla blib/script/mysqlsla
/usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/mysqlsla
Manifying blib/man3/mysqlsla.3pm
Installing /usr/lib/perl5/site_perl/5.8.8/mysqlsla.pm
Installing /usr/share/man/man3/mysqlsla.3pm
Installing /usr/bin/mysqlsla
Writing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/mysqlsla/.packlist
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
[root@Slave02 mysqlsla-2.03]# mysqls
mysqlshow  mysqlsla   
[root@Slave02 mysqlsla-2.03]# mysqls
mysqlshow  mysqlsla   
[root@Slave02 mysqlsla-2.03]# mysqlsla
Cannot auto-detect log type. Use option --log-type. at /usr/bin/mysqlsla line 2132.
[root@Slave02 mysqlsla-2.03]# mysqlsla help
Cannot auto-detect log type. Use option --log-type. at /usr/bin/mysqlsla line 2132.
[root@Slave02 mysqlsla-2.03]# mysqlsla --help
man mysqlsla for help or visit http://hackmysql.com/mysqlsla


[root@Slave02 mysqlsla-2.03]# mysqls
mysqlshow  mysqlsla   
[root@Slave02 mysqlsla-2.03]#

这里我开启相关的慢日志部分,把执行2条测试语句时间大于一秒即可(long_query_time=1)

[root@Slave02 mysqlsla-2.03]# mysqlsla -lt slow /usr/local/mysql/data/slow.log |more
Report for slow logs: /usr/local/mysql/data/slow.log
3 queries total, 3 unique
Sorted by 't_sum'
Grand Totals: Time 5 s, Lock 0 s, Rows sent 781.31k, Rows Examined 781.31k


______________________________________________________________________ 001 ___
Count : 1 (33.33%)
Time : 2.053846 s total, 2.053846 s avg, 2.053846 s to 2.053846 s max
(38.99%)
Lock Time (s) : 211 祍 total, 211 祍 avg, 211 祍 to 211 祍 max (38.16%)
Rows sent : 323.93k avg, 323.93k to 323.93k max (41.46%)
Rows examined : 323.93k avg, 323.93k to 323.93k max (41.46%)
Database : OEM
Users :
root@ 192.168.0.69 : 100.00% (1) of query, 100.00% (3) of all users

Query abstract:
SET timestamp=N; SELECT * FROM lot_sellform;

Query sample:
SET timestamp=1358906072;
select * from lot_sellform;

______________________________________________________________________ 002 ___
Count : 1 (33.33%)
Time : 2.018301 s total, 2.018301 s avg, 2.018301 s to 2.018301 s max (38.32%)
Lock Time (s) : 60 祍 total, 60 祍 avg, 60 祍 to 60 祍 max (10.85%)
Rows sent : 323.93k avg, 323.93k to 323.93k max (41.46%)
Rows examined : 323.93k avg, 323.93k to 323.93k max (41.46%)
Database :
Users :
root@ 192.168.0.69 : 100.00% (1) of query, 100.00% (3) of all users

Query abstract:
SET timestamp=N; SELECT * FROM lot_sellform t;

Query sample:
SET timestamp=1358906188;
select * from lot_sellform t;

______________________________________________________________________ 003 ___
Count : 1 (33.33%)
Time : 1.195229 s total, 1.195229 s avg, 1.195229 s to 1.195229 s max (22.69%)
Lock Time (s) : 282 祍 total, 282 祍 avg, 282 祍 to 282 祍 max (50.99%)
Rows sent : 133.45k avg, 133.45k to 133.45k max (17.08%)
Rows examined : 133.45k avg, 133.45k to 133.45k max (17.08%)
Database :
Users :
root@ 192.168.0.69 : 100.00% (1) of query, 100.00% (3) of all users

Query abstract:
SET timestamp=N; SELECT * FROM lot_chasingform;

Query sample:
SET timestamp=1358906109;
select * from lot_chasingform;
[root@Slave02 mysqlsla-2.03]#
[root@Slave02 mysqlsla-2.03]#
[root@Slave02 mysqlsla-2.03]#
[root@Slave02 mysqlsla-2.03]#

以上是相关的信息;参数说明如下:

总查询次数 (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语句

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值