一、tuning-primer.sh
mysql tuner-primer是检测mysql的主配置文件my.cnf的有力工具
现支持的调优:
Slow Query Log
Max Connections
Worker Threads
Memory Usage
Key Buffer
Query Cache
Sort Buffer
Joins
Temp Tables
Table (Open & Definition) Cache
Table Scans (read_buffer)
Table Locking
Innodb Status
1、下载(tuning-primer.sh)
https://launchpad.net/mysql-tuning-primer
使用方法:将tuning-primer.sh拷贝到my.cnf的同级目录执行:
[root@cy2 etc]# sh tuning-primer.sh
Using login values from ~/.my.cnf
- INITIAL LOGIN ATTEMPT FAILED -
Testing for stored webmin passwords:
None Found
Could not auto detect login info!
Found Sockets: /var/lib/mysql/mysql.sock//找到一个mysql.sock
Using: /var/lib/mysql/mysql.sock//使用这个.sock文件
Would you like to provide a different socket: [y/N] n//是否使用其他的socket
Do you have your login handy [y/N] : y//是否手动输入用户名和密码
User: root
Password:
Would you like me to create a ~/.my.cnf file for you [y/N] : n//是不是要帮你在创建一个my.cnf
注:如果没有出现结果,在 把用户名和密码放到my.cnf里面,如下即可正常执行脚本,运行完成后记得把用户密码这些敏感信息删除掉:
[root@localhost ~]# more ~/.my.cnf
[client]
user=root
password=123456
socket=/data/mysql/mysql_3306/tmp/mysql_3306.sock
[root@localhost ~]#
正常结果会显示报告建议:
ok,通过终端输入,可以显示出各种不通颜色的提示信息,非常人性化,对照参数提示,可以很简单的调整出最适合你的运行环境的配置文件
https://github.com/major/MySQLTuner-perl
1、Download/Installation
工具的下载及部署
解决环境依赖,因为工具是perl脚本开发的,需要perl脚本环境
# yun install -y perl*
wget http://mysqltuner.pl/ -O mysqltuner.pl
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/basic_passwords.txt -O basic_passwords.txt
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/vulnerabilities.csv -O vulnerabilities.csv
perl mysqltuner.plchmod +x mysqltuner.pl
执行脚本
perl mysqltuner.pl
针对给出的意见进行修改
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
Restrict Host for user@% to user@SpecificDNSorIp
MySQL started within last 24 hours - recommendations may be inaccurate
Reduce your overall MySQL memory footprint for system stability
Enable the slow query log to troubleshoot bad queries
Reduce or eliminate unclosed connections and network issues
Increasing the query_cache size over 128M may reduce performance
注意:
浏览输出的结果,特别是末尾的 Recommendations ,里面一般会提到您需要在 my.cnf 修改的内容。修改 my.cnf 后记得重启 MySQL 。重启后再运行 MySQLTuner 检查。另外需要注意的是 MySQL 需要启动 24 小时候再运行 MySQLTuner ,不然有些内容会不准。