This article is intended for Linux server administrators who want to analyse and tune MySQL/MariaDB using MySQLTuner. If your server is hosted with and managed by Maxer, please contact our support team and we can do this for you. Do not attempt these steps if you are unsure.
MySQLTuner is a read-only Perl script that inspects your MySQL/MariaDB server and prints recommendations based on runtime metrics. It supports MySQL, MariaDB, and Percona Server.
Step 1: Prepare for a meaningful run
For best results, let the database run under normal workload for 24–48 hours before trusting recommendations. Running immediately after a restart can produce misleading advice.
Step 2: Install MySQLTuner
Option A — via your distro (preferred):
-
RHEL/AlmaLinux/Rocky:
-
Debian/Ubuntu:
Option B — download the latest script directly:
Step 3: Run MySQLTuner safely
Credential handling (recommended):
-
MySQLTuner will automatically use credentials from option files such as
/root/.my.cnf
(or prompt you). Avoid putting passwords on the command line. -
If needed, point MySQLTuner at a specific option file:
Typical usages:
# Local server, let it auto-read /root/.my.cnf if present
mysqltuner
# Large installations: skip table size enumeration for speed
mysqltuner --skipsize
cPanel note: On most cPanel servers, /root/.my.cnf
already contains the MySQL root credentials, so simply run mysqltuner
as root.
Step 4: Interpret recommendations with care
-
Treat MySQLTuner’s advice as guidance, not absolute rules. Apply changes gradually and monitor.
-
Be mindful of version differences (e.g., MySQL 8 removed Query Cache; MariaDB still has it, but it’s usually best disabled).
-
Complement with other tools such as the slow query log,
SHOW GLOBAL STATUS
, or performance schema.
Step 5: Apply configuration changes
Edit your MySQL configuration and restart the service.
-
RHEL-like:
/etc/my.cnf.d/tuning.cnf
(or/etc/my.cnf
) -
Debian/Ubuntu:
/etc/mysql/conf.d/tuning.cnf
Then restart:
systemctl restart mysqld # RHEL/Alma/Rocky
systemctl restart mariadb # RHEL/Alma/Rocky (MariaDB)
systemctl restart mysql # Debian/Ubuntu
Security tip: if you use /root/.my.cnf
for client credentials, set strict permissions (0600). Do not put passwords directly on the command line or in shell history.
Step 6: Re-run and iterate
After making changes, let the server run under normal workload again, then re-run MySQLTuner and compare results. Expect several tuning cycles to reach a stable configuration.
Optional flags you might find useful
-
--skipsize
– speeds up checks on servers with many tables. -
--json
/--prettyjson
– machine-readable output for tickets/automation. -
--reportfile /path/file.txt
– save a report for later comparison.
Notes for cPanel servers
-
WHM Tuning Tool: Starting with recent versions of WHM, there is a built-in tool under:
WHM » Home » Database Services » Edit Database Configuration
This interface shows your current MySQL/MariaDB configuration and, if the database has been running for more than a few hours, it provides tuning suggestions based on observed performance.
More details: cPanel documentation – Edit Database Configuration. -
MySQLTuner vs WHM suggestions: The WHM tool is safer for administrators unfamiliar with tuning because it integrates with cPanel’s supported environment. You can still use MySQLTuner for deeper insights, but compare recommendations carefully before applying changes.
-
Typical large directories to watch on cPanel servers:
-
/var/lib/mysql
– databases -
/var/lib/mysql/.ibdata*
– InnoDB shared tablespaces (can grow large) -
/usr/local/cpanel/logs/
– cPanel-related logs
-
✅ You can now safely use MySQLTuner or WHM’s built-in configuration editor to review and adjust your database performance.
Updated by SP on 02/10/2025