Essential MySQL Performance Tuning Tools: MySQLTuner, Tuning‑Primer, and Percona Toolkit
This guide introduces four open‑source MySQL diagnostic utilities—MySQLTuner, tuning‑primer.sh, pt‑variable‑advisor, and pt‑query‑digest—explaining how to download, run them against a live server, interpret the generated AWR‑style reports, and apply the recommended configuration changes for better stability and speed.
MySQLTuner.pl
MySQLTuner is a Perl script that examines MySQL/MariaDB/Percona Server configuration, logs, storage engines and security settings, then outputs recommendations. Repository: https://github.com/major/MySQLTuner-perl
Download
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.plRun
chmod +x mysqltuner.pl
./mysqltuner.pl --socket /var/lib/mysql/mysql.sockThe script prompts for administrative credentials, then prints a report. Items marked [!!] indicate critical issues such as memory usage exceeding RAM. Review the “Recommendations” section to adjust my.cnf parameters.
tuning‑primer.sh
tuning‑primer is a Bash script that performs a health‑check of a MySQL instance and suggests configuration changes. Repository: https://github.com/BMDan/tuning-primer.sh
Download
wget https://launchpad.net/mysql-tuning-primer/trunk/1.6-r1/+download/tuning-primer.shRun
chmod +x tuning-primer.sh
./tuning-primer.shThe script prints a header “MYSQL PERFORMANCE TUNING PRIMER” and then a series of sections: overall statistics, query‑group statistics, and per‑query metrics. Red‑flag warnings and the final “Recommendations” block guide adjustments to variables, indexes, and my.cnf.
pt‑variable‑advisor
Part of Percona Toolkit, pt-variable-advisor inspects MySQL system variables and flags values that may degrade performance or security.
Installation
# Example for RHEL/CentOS 7
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
tar -xf percona-toolkit-3.0.13-re85ce15-el7-x86_64-bundle.tar
yum install percona-toolkit-3.0.13-re85ce15.el7.x86_64.rpmRun
pt-variable-advisor --socket /var/lib/mysql/mysql.sockThe output lists each variable, the recommended value, and a WARN tag for out‑of‑range settings. Adjust the flagged variables in my.cnf and restart MySQL.
pt‑query‑digest
pt-query-digestparses MySQL slow‑query logs, process lists, or tcpdump captures and produces a statistical summary.
Typical usage examples
Analyze a slow‑query log file:
pt-query-digest /var/lib/mysql/slow.log > slow_report.logAnalyze the last 12 hours:
pt-query-digest --since=12h /var/lib/mysql/slow.log > slow_report_12h.logAnalyze a specific time window:
pt-query-digest --since='2023-01-07 09:30:00' --until='2023-01-07 10:00:00' /var/lib/mysql/slow.log > slow_report_window.logFilter only SELECT statements:
pt-query-digest --filter '$event->{fingerprint} =~ m/^select/i' /var/lib/mysql/slow.log > select_report.logFilter queries run by the root user:
pt-query-digest --filter '($event->{user} || "") =~ m/^root/i' /var/lib/mysql/slow.log > root_report.logFind full table scans or full joins:
pt-query-digest --filter '(($event->{Full_scan} || "") eq "yes") || (($event->{Full_join} || "") eq "yes")' /var/lib/mysql/slow.log > scan_report.logThe generated report consists of three parts:
Overall statistics (total queries, time range, unique queries, min/avg/max times, 95th percentile, median).
Query‑group statistics (rank, total response time, call count, average per call, variance‑to‑mean ratio).
Per‑query details (query ID, databases, user distribution, time distribution, tables involved, EXPLAIN output).
Use the WARN entries to identify slow or inefficient queries and adjust indexes or query patterns accordingly.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
