您的位置:首页 > 数据库 > MySQL

使用MySQLTuner脚本检测、优化MySQL数据库

2018-01-17 10:46 429 查看
MySQLTuner 是一个 Perl 脚本,可以用来分析您的 MySQL 性能,并且基于收集到的信息给出相应的优化建议。这样子,您就可以调整 my.cnf 从而优化您的 MySQL 设置。

这边只是介绍使用方法,不保证说 MySQLTuner 对您就是绝对有效。

首先需要下载 MySQLTuner

wget https://raw.github.com/major/MySQLTuner-perl/master/mysqltuner.pl

设置权限为可执行

chmod +x mysqltuner.pl

然后就可以直接运行了

./mysqltuner.pl

如果遇到错误 Unable to find mysqladmin in your $PATH 可以输入

PATH=$PATH:/usr/local/mysql/bin

PS:把 /usr/local/mysql/bin 改为您 MySQL 程序 mysqladmin 的路径

运行后的内容如下:
./mysqltuner.pl --user root --pass nongyao001 --socket /tmp/mysq.sock

General recommendations:
Control warning line(s) into /www/wdlinux/mysql-5.5.48/data/cent98.dt50.cn.err file
Control error line(s) into /www/wdlinux/mysql-5.5.48/data/cent98.dt50.cn.err file
Run OPTIMIZE TABLE to defragment tables for better performance
OPTIMIZE TABLE west.destoon_article_data_21; -- can free 158.651298522949 MB
Total freed space after theses OPTIMIZE TABLE : 158.651298522949 Mb
Restrict Host for user@% to user@SpecificDNSorIp
Reduce your overall MySQL memory footprint for system stability
Dedicate this server to your database for highest performance.
Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Variables to adjust:
MySQL's maximum memory usage is dangerously high
Add RAM before increasing MySQL buffer variables
query_cache_type (=0)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
innodb_buffer_pool_instances(=4)

浏览输出的结果,特别是末尾的 Recommendations ,里面一般会提到您需要在 my.cnf 修改的内容。修改 my.cnf 后记得重启 MySQL 。重启后再运行 MySQLTuner 检查。另外需要注意的是 MySQL 需要启动 24 小时候再运行 MySQLTuner ,不然有些内容会不准。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  优化