4 款 MySQL 调优工具,公司大神都在用!
JAVA葵花宝典
共 4552字,需浏览 10分钟
·
2021-08-10 14:01
阅读本文大概需要 4 分钟。
来自:toutiao.com/a6691523026984370699
![](https://filescdn.proginn.com/d087130781d82857a384121664a227a6/8da312cce2feaa72787ec4c20b2a6ca8.webp)
mysqltuner.pl
项目地址:https://github.com/major/MySQLTuner-perl
1.1 下载
[root@localhost ~]#wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
1.2 使用
[root@localhost ~]# ./mysqltuner.pl --socket /var/lib/mysql/mysql.sock
>> MySQLTuner 1.7.4 - Major Hayden <major@mhtx.net>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password: [OK] Currently running supported MySQL version 5.7.23
[OK] Operating on 64-bit architecture
1.3、报告分析
![](https://filescdn.proginn.com/621438d158ac36826ddc622f9dcd2dfa/0e121efce60ab617cad6253336294ab1.webp)
![](https://filescdn.proginn.com/5098ed4972da5a70c902df4373e8fc8c/6b4c5d7b1e4bae6a0fef147e5819fef6.webp)
tuning-primer.sh
项目地址:https://github.com/BMDan/tuning-primer.sh
![](https://filescdn.proginn.com/2a6a85c5643548718a67125b1846b0d5/9d2895e8589d467e614c4c3c30dc895d.webp)
2.1 下载
[root@localhost ~]#wget https://launchpad.net/mysql-tuning-primer/trunk/1.6-r1/+download/tuning-primer.sh
2.2 使用
[root@localhost ~]# [root@localhost dba]# ./tuning-primer.sh
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
2.3 报告分析
![](https://filescdn.proginn.com/3b4b3ab88e77bededc9b21030cab8ffd/a0aec6dd6935a72ebc6b4223cbaa498c.webp)
pt-variable-advisor
3.1 安装
https://www.percona.com/downloads/percona-toolkit/LATEST/
[root@localhost ~]#wget https://www.percona.com/downloads/percona-toolkit/3.0.13/binary/redhat/7/x86_64/percona-toolkit-3.0.13-re85ce15-el7-x86_64-bundle.tar
[root@localhost ~]#yum install percona-toolkit-3.0.13-1.el7.x86_64.rpm
3.2 使用
[root@localhost ~]# pt-variable-advisor localhost --socket /var/lib/mysql/mysql.sock
3.3 报告分析
![](https://filescdn.proginn.com/40e96995652d5364c07b4d22211d7a67/b705bedc08d845235da204a6cdf0a7d6.webp)
pt-qurey-digest
4.1安装
4.2使用
[root@localhost ~]# pt-query-digest /var/lib/mysql/slowtest-slow.log
4.3 常见用法分析
pt-query-digest /var/lib/mysql/slowtest-slow.log > slow_report.log
pt-query-digest --since=12h /var/lib/mysql/slowtest-slow.log > slow_report2.log
pt-query-digest /var/lib/mysql/slowtest-slow.log --since '2017-01-07 09:30:00' --until '2017-01-07 10:00:00'> > slow_report3.log
pt-query-digest --filter '$event->{fingerprint} =~ m/^select/i' /var/lib/mysql/slowtest-slow.log> slow_report4.log
pt-query-digest --filter '($event->{user} || "") =~ m/^root/i' /var/lib/mysql/slowtest-slow.log> slow_report5.log
pt-query-digest --filter '(($event->{Full_scan} || "") eq "yes") ||(($event->{Full_join} || "") eq "yes")' /var/lib/mysql/slowtest-slow.log> slow_report6.log
4.4 报告分析
Overall:总共有多少条查询
Time range:查询执行的时间范围
unique:唯一查询数量,即对查询条件进行参数化以后,总共有多少个不同的查询
total:总计
min:最小
max:最大
avg:平均
95%:把所有值从小到大排列,位置位于95%的那个数,这个数一般最具有参考价值
median:中位数,把所有值从小到大排列,位置位于中间那个数
Rank:所有语句的排名,默认按查询时间降序排列,通过--order-by指定
Query ID:语句的ID,(去掉多余空格和文本字符,计算hash值)
Response:总的响应时间
time:该查询在本次分析中总的时间占比
calls:执行次数,即本次分析总共有多少条这种类型的查询语句
R/Call:平均每次执行的响应时间
V/M:响应时间Variance-to-mean的比率
Item:查询对象
ID:查询的ID号,和上图的Query ID对应
Databases:数据库名
Users:各个用户执行的次数(占比)
Query_time distribution :查询时间分布, 长短体现区间占比。
Tables:查询中涉及到的表
Explain:SQL语句
评论