【MySql】 慢日志查询工具之mysqlsla
2023-09-14 08:57:29 时间
mysqlsla 是一款由hackmysql.com推出的一款日志分析工具,功能非常强大. 图形输出数据报表,非常有利于分析慢查询的原因, 包括执行频率, 数据量, 查询消耗等!
[root@rac3 software]# wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz
[root@rac3 software]# tar zvxf mysqlsla-2.03.tar.gz
[root@rac3 software]# mv mysqlsla-2.03 mysqlsla
[root@rac3 software]# cd mysqlsla
[root@rac3 mysqlsla]# ls
bin Changes INSTALL lib Makefile.PL MANIFEST META.yml README
Makefile.PL MANIFEST META.yml
[root@rac3 mysqlsla]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for mysqlsla
[root@rac3 mysqlsla]#
[root@rac3 mysqlsla]# 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/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/mysqlsla/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod 在mysql中执行查询语句,之后使用mysqlsla 工具查询 [root@rac3 bin]# mysqlsla /opt/mysql/data/slowquery.log
Auto-detected logs as slow logs
Report for slow logs: /opt/mysql/data/slowquery.log
3 queries total, 3 unique
Sorted by t_sum
Grand Totals: Time 1 s, Lock 0 s, Rows sent 2, Rows Examined 1.00M
______________________________________________________________________ 001 ___
Count : 1 (50.00%)
Time : 634.32 ms total, 634.32 ms avg, 634.32 ms to 634.32 ms max (98.09%)
Lock Time (s) : 107.011 ms total, 107.011 ms avg, 107.011 ms to 107.011 ms max (98.71%)
Rows sent : 1 avg, 1 to 1 max (50.00%)
Rows examined : 1.00M avg, 1.00M to 1.00M max (99.80%)
Database : test
Users :
root@localhost : 100.00% (1) of query, 100.00% (2) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest;
Query sample:
SET timestamp=1329572756;
select count(1) from sbtest;
______________________________________________________________________ 002 ___
Count : 1 (50.00%)
Time : 12.356 ms total, 12.356 ms avg, 12.356 ms to 12.356 ms max (1.91%)
Lock Time (s) : 1.403 ms total, 1.403 ms avg, 1.403 ms to 1.403 ms max (1.29%)
Rows sent : 1 avg, 1 to 1 max (50.00%)
Rows examined : 2.00k avg, 2.00k to 2.00k max (0.20%)
Database :
Users :
root@localhost : 100.00% (1) of query, 100.00% (2) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest ,t1 WHERE t1.id=sbtest.id;
Query sample:
SET timestamp=1329572815;
select count(1) from sbtest ,t1 where t1.id=sbtest.id; ______________________________________________________________________ 003 ___ Count : 1 (33.33%)
Time : 12.356 ms total, 12.356 ms avg, 12.356 ms to 12.356 ms max (0.00%)
Lock Time (s) : 1.403 ms total, 1.403 ms avg, 1.403 ms to 1.403 ms max (1.29%)
Rows sent : 1 avg, 1 to 1 max (33.33%)
Rows examined : 2.00k avg, 2.00k to 2.00k max (0.20%)
Database :
Users :
root@localhost : 100.00% (1) of query, 100.00% (3) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest ,t1 WHERE t1.id=sbtest.id;
Query sample:
SET timestamp=1329572815;
select count(1) from sbtest ,t1 where t1.id=sbtest.id; 输出解释: queries total 总查询次数
unique 去除重复后的 sql 数量.
Sorted by 输出报表的内容排序.
Grand Totals slow sql 统计信息包括: 总执行时间, 等待锁时间, 结果行总数, 扫描行总数.
Count slow sql 的执行次数及占总的 slow log 数量的百分比.
Time 执行时间, 包括总时间, 平均时间, 最小, 最大时间, 时间占到总 slow sql 时间的百分比.
Lock Time 等待锁的时间.
Rows sent 结果行统计数量, 包括平均, 最小, 最大数量.
Rows examined 扫描的行数量.
Database 属于哪个数据库
Users username@hostname 执行sql的用户
Query abstract 精简后的sql语句
--log-type=type logs or -lt type logs 其中type logs 可为 slow, general, binary, msl or udl. 官方文档说是没有指定时, 会根据给定的日志文件自动检测, 但测试时失败, so, 最好指定该参数. msl 是指 microslow patched 的慢日志. udl 用户自定义的日志. binary 因为 mysqlsla 不能直接解析 MySQL 的 binary log, 所以需先用 mysqlbinlog命令将其解析为文本. mysqlbinlog带有--short-form参数时, 则 LOG TYPE 需指定为 udl. 命令可类似于如下: mysqlbinlog /opt/mysql/data/mysql-bin.000001 | mysqlsla -lt binary - mysqlbinlog --short-form. /opt/mysql/data/mysql-bin.000001 | mysqlsla -lt udl - --explain or -ex explain 每句 SQL, 默认没有启用 --databases=dbname1,dbnam2[,...] or -db dbname1,dbnam2[,...] or -D dbname1,dbnam2[,...]用于 --explain --flush-qc 强制刷新查询缓存, 默认没有启用 --grep="PATTERN" 只解析满足条件的 SQL --meta-filter="CONDTIONS" or -mf "CONDTIONS" CONDITIONS 格式为[meta][op][value],多个条件时, 中间以,分割. [meta] 查看这里 [op] , r =. 当 [meta] 是基于字符串时, [op] 只能是 =. [value] 数字 or 字符串. --reports=REPORTS or -R REPORTS, 默认是 standard, REPORTS 可以是以,为分割的列表. 可选选项:standard, time-all, print-unique, print-all, dump
[root@rac3 software]# tar zvxf mysqlsla-2.03.tar.gz
[root@rac3 software]# mv mysqlsla-2.03 mysqlsla
[root@rac3 software]# cd mysqlsla
[root@rac3 mysqlsla]# ls
bin Changes INSTALL lib Makefile.PL MANIFEST META.yml README
Makefile.PL MANIFEST META.yml
[root@rac3 mysqlsla]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for mysqlsla
[root@rac3 mysqlsla]#
[root@rac3 mysqlsla]# 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/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/mysqlsla/.packlist
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod 在mysql中执行查询语句,之后使用mysqlsla 工具查询 [root@rac3 bin]# mysqlsla /opt/mysql/data/slowquery.log
Auto-detected logs as slow logs
Report for slow logs: /opt/mysql/data/slowquery.log
3 queries total, 3 unique
Sorted by t_sum
Grand Totals: Time 1 s, Lock 0 s, Rows sent 2, Rows Examined 1.00M
______________________________________________________________________ 001 ___
Count : 1 (50.00%)
Time : 634.32 ms total, 634.32 ms avg, 634.32 ms to 634.32 ms max (98.09%)
Lock Time (s) : 107.011 ms total, 107.011 ms avg, 107.011 ms to 107.011 ms max (98.71%)
Rows sent : 1 avg, 1 to 1 max (50.00%)
Rows examined : 1.00M avg, 1.00M to 1.00M max (99.80%)
Database : test
Users :
root@localhost : 100.00% (1) of query, 100.00% (2) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest;
Query sample:
SET timestamp=1329572756;
select count(1) from sbtest;
______________________________________________________________________ 002 ___
Count : 1 (50.00%)
Time : 12.356 ms total, 12.356 ms avg, 12.356 ms to 12.356 ms max (1.91%)
Lock Time (s) : 1.403 ms total, 1.403 ms avg, 1.403 ms to 1.403 ms max (1.29%)
Rows sent : 1 avg, 1 to 1 max (50.00%)
Rows examined : 2.00k avg, 2.00k to 2.00k max (0.20%)
Database :
Users :
root@localhost : 100.00% (1) of query, 100.00% (2) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest ,t1 WHERE t1.id=sbtest.id;
Query sample:
SET timestamp=1329572815;
select count(1) from sbtest ,t1 where t1.id=sbtest.id; ______________________________________________________________________ 003 ___ Count : 1 (33.33%)
Time : 12.356 ms total, 12.356 ms avg, 12.356 ms to 12.356 ms max (0.00%)
Lock Time (s) : 1.403 ms total, 1.403 ms avg, 1.403 ms to 1.403 ms max (1.29%)
Rows sent : 1 avg, 1 to 1 max (33.33%)
Rows examined : 2.00k avg, 2.00k to 2.00k max (0.20%)
Database :
Users :
root@localhost : 100.00% (1) of query, 100.00% (3) of all users
Query abstract:
SET timestamp=N; SELECT COUNT(N) FROM sbtest ,t1 WHERE t1.id=sbtest.id;
Query sample:
SET timestamp=1329572815;
select count(1) from sbtest ,t1 where t1.id=sbtest.id; 输出解释: queries total 总查询次数
unique 去除重复后的 sql 数量.
Sorted by 输出报表的内容排序.
Grand Totals slow sql 统计信息包括: 总执行时间, 等待锁时间, 结果行总数, 扫描行总数.
Count slow sql 的执行次数及占总的 slow log 数量的百分比.
Time 执行时间, 包括总时间, 平均时间, 最小, 最大时间, 时间占到总 slow sql 时间的百分比.
Lock Time 等待锁的时间.
Rows sent 结果行统计数量, 包括平均, 最小, 最大数量.
Rows examined 扫描的行数量.
Database 属于哪个数据库
Users username@hostname 执行sql的用户
Query abstract 精简后的sql语句
--log-type=type logs or -lt type logs 其中type logs 可为 slow, general, binary, msl or udl. 官方文档说是没有指定时, 会根据给定的日志文件自动检测, 但测试时失败, so, 最好指定该参数. msl 是指 microslow patched 的慢日志. udl 用户自定义的日志. binary 因为 mysqlsla 不能直接解析 MySQL 的 binary log, 所以需先用 mysqlbinlog命令将其解析为文本. mysqlbinlog带有--short-form参数时, 则 LOG TYPE 需指定为 udl. 命令可类似于如下: mysqlbinlog /opt/mysql/data/mysql-bin.000001 | mysqlsla -lt binary - mysqlbinlog --short-form. /opt/mysql/data/mysql-bin.000001 | mysqlsla -lt udl - --explain or -ex explain 每句 SQL, 默认没有启用 --databases=dbname1,dbnam2[,...] or -db dbname1,dbnam2[,...] or -D dbname1,dbnam2[,...]用于 --explain --flush-qc 强制刷新查询缓存, 默认没有启用 --grep="PATTERN" 只解析满足条件的 SQL --meta-filter="CONDTIONS" or -mf "CONDTIONS" CONDITIONS 格式为[meta][op][value],多个条件时, 中间以,分割. [meta] 查看这里 [op] , r =. 当 [meta] 是基于字符串时, [op] 只能是 =. [value] 数字 or 字符串. --reports=REPORTS or -R REPORTS, 默认是 standard, REPORTS 可以是以,为分割的列表. 可选选项:standard, time-all, print-unique, print-all, dump
相关文章
- 在iOS上搭建MySQL数据库连接(ios连接mysql数据库)
- MySQL数据生成神器:一个全新的体验(mysql数据生成工具)
- 轻松导入:MySQL数据库的简单工具(mysql导入工具)
- 无法正常工作Mysql .exe出现异常,无法正常运行(mysql.exe)
- 器中的日志如何清除MySQL服务器中的日志记录(清除mysql服务)
- MySQL数据库日志:深入分析与管理(mysql数据库日志分析)
- 使用MySQL关系图工具搭建数据库架构(mysql关系图工具)
- MYSQL启用日志,查看日志,利用mysqlbinlog工具恢复MySQL数据库
- 如何解决MySQL命令行闪退问题(mysql命令闪退)
- 便捷的MySQL数据库打开工具介绍(mysql数据库打开工具)
- 如何开启MySQL慢日志并优化数据库性能?(mysql开启慢日志)
- 无法载入MySQL扩展:解决办法来了!(无法载入mysql扩展)
- MySQL外键与连接详解(mysql外键连接)
- Mysql记录慢查询日志:开启追踪系统性能问题(mysql开启慢查询日志)
- MySQL日志恢复:让数据活跃起来(mysql 日志恢复数据)
- MySQL数据库连接简易之工具(连接mysql数据库工具)
- 极速升级:利用Oracle迁移MySQL快速迁移数据(oracle迁移mysql工具)
- MySQL数据库同步解决方案:一键就完成!(mysql数据库同步工具)
- MySQL中Redo日志 数据恢复的利器(mysql中redo日志)
- MySQL中NUM类型详解数据类型及其使用方法(mysql中num类型)
- MySQL教你如何使用两表完全连接(mysql 两表完全连接)
- MySQL 一万个客户端,如何优化数据库性能(mysql一万个客户端)
- MySQL怎么不卸载直接覆盖详细操作步骤(mysql不卸载直接覆盖)