mysqlsla是一个慢日志分析工具了,我们可以把慢日志对过mysqlsla进行分析从而得出性能最差的sql语句了,下面我们一起来看看吧,mysqlsla是hackmysql.com推出的一款mysql的日志分析工具,功能非常强大,数据报表,非常有利于分析慢查询的原因,包括执行频率,数据量,查询消耗等.
一、使用mysqlsla -lt slow mysql-slow.log 或者 mysqlsla -lt slow mysql-slow.log -sf “+SELECT” -db dbName -top 10 -sort t_sum
参数意义
lt:表示日志类型,有slow, general, binary, msl, udl。
sf:[+-][type],[TYPE]有SELECT, CREATE, DROP, UPDATE, INSERT,例如”+SELECT,INSERT”,不出现的默认是-,即不包括。
db:要处理哪个库的日志。
top:表示取按规则排序的前多少条。
sort:按某种规则排序,t_sum按总时间排序, c_sum按总次数排序。
二、分析结果
总查询次数(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语句
三、安装
方法一:从http://hackmysql.com/mysqlsla下载mysqlsla,当前最新版为:2.03
tar zxvf mysqlsla-2.03.tar.gz
cp mysqlsla-2.03/bin/mysqlsla /usr/local/bin
如果提示“Can’t locate DBI.pm”,执行以下命令:
yum install perl-DBI perl-DBD-MySQL -y
这时就可以使用mysqlsla了,用法如下:mysqlsla -lt slow slow.log
方法二:
- wgethttp://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
- #tarxzvfmysqlsla-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
- #cdmysqlsla-2.03
- #ll
- 总计68
- drwxr-xr-x21000100040962008-11-11bin
- -rw-r–r–11000100056302008-11-11Changes
- -rw-r–r–1100010003942008-07-13INSTALL
- drwxr-xr-x21000100040962008-11-11lib
- -rw-r–r–1100010003892008-07-13Makefile.PL
- -rw-r–r–1100010001522008-07-13MANIFEST
- -rw-r–r–1100010003032008-11-11META.yml
- -rw-r–r–11000100019692008-11-11README
- #lessINSTALL
- Installingmysqlsla
- ===================
- perlMakefile.PL
- make
- makeinstall
- Dependingonyoursystem,themysqlslascriptwillbecopiedtosomecommonbin
- directory(/usr/local/bin/forexample).Thenyoushouldbeabletorunitfrom
- thecommandlinelike:mysqlsla-ltslowLOG
- Forquickhelp,manmysqlsla
- Foralldocumentationandguides,visithttp://hackmysql.com/mysqlsla
- #lessMakefile.PL
- use5.008004;
- useExtUtils::MakeMaker;
- WriteMakefile(
- NAME=>‘mysqlsla’,
- VERSION_FROM=>‘lib/mysqlsla.pm’,
- PREREQ_PM=>{},
- ($]>=5.005?
- (ABSTRACT_FROM=>‘lib/mysqlsla.pm’,#retrieveabstractfrommodule
- AUTHOR=>‘DanielNichter(http://hackmysql.com/contact)’):()),
- EXE_FILES=>['bin/mysqlsla'],
- );
- #perlMakefile.PL
- Checkingifyourkitiscomplete…
- Looksgood
- WritingMakefileformysqlsla
- #ll
- 总计96
- drwxr-xr-x21000100040962008-11-11bin
- -rw-r–r–11000100056302008-11-11Changes
- -rw-r–r–1100010003942008-07-13INSTALL
- drwxr-xr-x21000100040962008-11-11lib
- -rw-r–r–1rootroot2272209-0818:52Makefile
- -rw-r–r–1100010003892008-07-13Makefile.PL
- -rw-r–r–1100010001522008-07-13MANIFEST
- -rw-r–r–1100010003032008-11-11META.yml
- -rw-r–r–11000100019692008-11-11README
- --phpfensi.com
- #make
- cplib/mysqlsla.pmblib/lib/mysqlsla.pm
- cpbin/mysqlslablib/script/mysqlsla
- /usr/bin/perl“-MExtUtils::MY”-e“MY->fixin(shift)”blib/script/mysqlsla
- Manifyingblib/man3/mysqlsla.3pm
- #makeinstall
- 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
- Appendinginstallationinfoto/usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
默认将命令mysqlsla安装到/usr/bin目录,执行mysqlsla –help时提示没有安装DBI模块,mysqlsla是用perl写的,第一次通过CPAN安装perl模块时,需要进行相关的配置,大部分配置采用默认值,一路回车即可.
#perl -MCPAN -e Shell
然后在下面的各个询问中可以改已经配置好的选项,然后执行下面的命令保存.
CPAN>reload index
CPAN>reload cpan
安装DBI模块:CPAN>install DBI
如果是第一次以后进入CPAN系统,想修改以前的配置,可以在CPAN命令行(即CPAN>)键入以下指令:
CPAN>o conf init
同时要执行下面的命令保存:
CPAN>reload index
CPAN>reload cpan
man mysqlsla可以看到mysqlsla的相关选项:
- #manmysqlsla
- XXX
- XXXWARNING:oldcharacterencodingand/orcharacterset
- XXX
- mysqlsla(3)UserContributedPerlDocumentationmysqlsla(3)
- NAME
- mysqlsla–Parse,filter,analyzeandsortMySQLslow,generalandbinarylogs
- SYNOPSIS
- #Basicoperation:parseaMySQLsloworgenerallog
- mysqlsla–log-typeslowLOG
- mysqlsla–log-typegeneralLOG
- #Parseoutputfrommysqlbinlog
- #mysqlslacannotdirectlyparsebinarylogs
- mysqlbinlogLOG│mysqlsla–log-typebinary-
- #Parseamicroslowpatchedslowlog
- mysqlsla–log-typemslLOG
- #Replayareplayfile
- mysqlsla–replayFILE
- #Parseauser-definedlogspecifyitsformat
- mysqlsla–log-typeudl–udl-formatFILE
- #Letmysqlslaautomaticallydeterminethelogtype
- mysqlslaLOG
- DESCRIPTION
- mysqlslaparses,filters,analyzesandsortsMySQLslow,general,binaryandmicroslowpatchedslowlogs.
- Italsosupportsuser-definedlogs.
- ThisPOD/manpageisonlyaverybriefoutlineofusageandcommandlineoptions.Forthefulllibraryof
- mysqlsladocumentationvisithttp://hackmysql.com/mysqlsla.
- #mysqlsla/tmp/mysqlslow.log|less
- Auto-detectedlogsasslowlogs
- Reportforslowlogs:/tmp/mysqlslow.log
- 6queriestotal,6unique
- Sortedby‘t_sum’
- GrandTotals:Time0s,Lock0s,Rowssent13,RowsExamined13
- ______________________________________________________________________001___
- Count:1(16.67%)
- Time:2.321mstotal,2.321msavg,2.321msto2.321msmax(47.20%)
- LockTime(s):629?stotal,629?savg,629?sto629?smax(77.75%)
- Rowssent:8avg,8to8max(61.54%)
- Rowsexamined:8avg,8to8max(61.54%)
- Database:
- Users:
- root@192.168.1.100:100.00%(1)ofquery,100.00%(6)ofallusers
- Queryabstract:
- SETtimestamp=N;SHOWvariablesLIKE‘S’;
- Querysample:
- SETtimestamp=1252395365;
- showvariableslike‘%character%’;
- ……
格式说明如下:
总查询次数(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语句
除了以上的输出,官方还提供了很多定制化参数,是一款不可多得的好工具.