MySQLTuner Guide: Optimize MySQL Server Performance
Learn how to analyze, tune and optimize MySQL servers using MySQLTuner. This production-focused guide covers memory tuning, InnoDB optimization, slow query analysis and best practices.

What Is MySQLTuner?
MySQLTuner is a popular Perl script that analyzes your MySQL server and provides recommendations for improving performance, memory utilization, indexing and overall database health.
Before You Begin
For accurate recommendations, MySQL should ideally be running under normal production load for at least 24 hours before running MySQLTuner.
Important
Do not blindly apply every recommendation. Always understand the impact of configuration changes before modifying production systems.
Step 1 — Download MySQLTuner
wget https://github.com/major/MySQLTuner-perl/releases/download/v2.8.45/mysqltuner.pl
chmod +x mysqltuner.plStep 2 — Run MySQLTuner
./mysqltuner.plEnter your MySQL administrative credentials when prompted.
Example Output
[OK] Maximum reached memory usage: 5.8G
[!!] Query cache should be disabled
[!!] Temporary tables created on disk: 28%
[OK] InnoDB buffer pool / data size: 8.0G / 6.2G
[!!] Slow queries: 5%
[OK] Table cache hit rate: 99%
[OK] Connections usage: 12%Understanding The Results
| Result | Meaning |
|---|---|
| [OK] | Healthy Configuration |
| [!!] | Requires Investigation |
| Memory Usage | Potential RAM Bottlenecks |
| Slow Queries | Optimization Opportunities |
Step 3 — Check Current MySQL Variables
mysql -u root -p
SHOW VARIABLES;Step 4 — Backup Configuration
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.backupInnoDB Buffer Pool Optimization
The InnoDB Buffer Pool is one of the most important MySQL settings. It caches data and indexes in memory, reducing disk reads and dramatically improving performance.
Recommended Buffer Pool Size
- ✓ Dedicated MySQL Server → 70% to 80% of RAM
- ✓ Shared Server → 30% to 50% of RAM
- ✓ VPS Running Applications → 40% to 60% of RAM
Example: 16GB RAM Server
innodb_buffer_pool_size = 12GCheck Current Buffer Pool
SHOW VARIABLES LIKE 'innodb_buffer_pool_size';Step 5 — Optimize InnoDB Log Files
Larger redo logs improve write performance and reduce checkpoint pressure on busy databases.
innodb_log_file_size = 1G
innodb_log_buffer_size = 64MNote
Restart MySQL after changing InnoDB log file sizes.
Step 6 — Disable Query Cache (MySQL 5.7)
MySQLTuner frequently recommends disabling query cache because it often becomes a bottleneck on busy servers.
query_cache_type = 0
query_cache_size = 0MySQL 8 completely removed Query Cache.
Step 7 — Optimize Max Connections
Many servers waste memory because max_connections is configured too high.
Check Usage
SHOW STATUS LIKE 'Max_used_connections';Example
Max_used_connections = 85
max_connections = 500If your peak usage is 85, setting 500 connections wastes RAM unnecessarily.
Recommended
max_connections = 150Step 8 — Temporary Table Optimization
MySQLTuner often reports excessive temporary tables being written to disk.
Check Statistics
SHOW GLOBAL STATUS LIKE 'Created_tmp%';Improve Memory Limits
tmp_table_size = 256M
max_heap_table_size = 256MGoal
Keep temporary disk tables below 25% whenever possible.
Step 9 — Table Cache Optimization
If MySQL repeatedly opens tables, increasing table cache can improve performance.
SHOW GLOBAL STATUS LIKE 'Opened_tables';Example Setting
table_open_cache = 4000Example Production my.cnf
Example for a 16GB dedicated MySQL server.
[mysqld]
innodb_buffer_pool_size = 12G
innodb_log_file_size = 1G
innodb_log_buffer_size = 64M
max_connections = 150
tmp_table_size = 256M
max_heap_table_size = 256M
table_open_cache = 4000
innodb_flush_method = O_DIRECT
skip-name-resolveValidate Configuration
mysqld --verbose --help > /dev/nullRestart MySQL
sudo systemctl restart mysqlVerify Server Health
sudo systemctl status mysqlSlow Query Analysis
MySQLTuner frequently reports slow query percentages. Optimizing slow queries often provides greater performance improvements than increasing server resources.
Common Slow Query Causes
- ❌ Missing Indexes
- ❌ SELECT *
- ❌ Large Table Scans
- ❌ Unoptimized JOINs
- ❌ Excessive Sorting
- ❌ Poor Schema Design
Step 10 — Enable Slow Query Log
Add these settings to your MySQL configuration.
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log_queries_not_using_indexes = 1Restart MySQL
sudo systemctl restart mysqlVerify Settings
SHOW VARIABLES LIKE '%slow_query%';Step 11 — Analyze Slow Query Log
mysqldumpslow -s t /var/log/mysql/mysql-slow.logThis displays the slowest queries first.
Top 20 Slow Queries
mysqldumpslow -s t -t 20 /var/log/mysql/mysql-slow.logStep 12 — Install Percona Toolkit
Percona Toolkit provides deeper analysis than mysqldumpslow.
sudo apt update
sudo apt install percona-toolkit -yAnalyze Slow Queries
pt-query-digest /var/log/mysql/mysql-slow.logStep 13 — Find Missing Indexes
Missing indexes are one of the most common causes of poor database performance.
SHOW INDEX FROM users;Example Slow Query
SELECT *
FROM users
WHERE email = '[email protected]';Add Index
CREATE INDEX idx_users_email
ON users(email);Step 14 — Use EXPLAIN
EXPLAIN shows how MySQL executes queries.
EXPLAIN
SELECT *
FROM users
WHERE email = '[email protected]';Good Result
type: ref
key: idx_users_email
rows: 1Bad Result
type: ALL
key: NULL
rows: 500000A query using type=ALL is usually performing a full table scan.
Step 15 — Monitor InnoDB Health
SHOW ENGINE INNODB STATUSGThis provides valuable information about locks, transactions and buffer pool performance.
Step 16 — Check Buffer Pool Efficiency
SHOW GLOBAL STATUS
LIKE 'Innodb_buffer_pool_read%';Target
Buffer Pool Hit Ratio > 99%High CPU Troubleshooting
Common Causes
- ❌ Missing Indexes
- ❌ Large Table Scans
- ❌ Excessive Sorting
- ❌ Too Many Connections
- ❌ Poor Queries
Fixes
- ✓ Add Indexes
- ✓ Optimize Queries
- ✓ Tune Buffer Pool
- ✓ Reduce Connections
- ✓ Enable Query Analysis
Memory Usage Formula
One of the most useful MySQLTuner outputs is maximum potential memory usage.
Total Memory ≈
Global Buffers
+
(max_connections × per-thread buffers)Example
Buffer Pool = 12G
max_connections = 150
Per Thread = 4M
Total ≈ 12.6GCloudRevol Recommendation
Before increasing server RAM, analyze slow queries, optimize indexes and tune InnoDB settings. In most environments, query optimization delivers significantly larger performance gains than simply adding hardware.
Production Optimization Checklist
Use this checklist after running MySQLTuner to ensure your MySQL server is optimized for production workloads.
Recommended MySQL Settings By Server Size
| RAM | Buffer Pool | Max Connections | Log File Size |
|---|---|---|---|
| 4GB | 2G | 100 | 512M |
| 8GB | 5G | 150 | 1G |
| 16GB | 12G | 200 | 1G |
| 32GB | 24G | 250 | 2G |
| 64GB | 48G | 300 | 4G |
WordPress & WooCommerce Optimization
WooCommerce stores generate many database queries, especially during checkout, cart updates and product searches.
- ✓ Increase InnoDB Buffer Pool
- ✓ Use Redis Object Cache
- ✓ Optimize wp_options Table
- ✓ Remove Expired Transients
- ✓ Enable Slow Query Logging
- ✓ Optimize Product Indexes
Laravel MySQL Optimization
Laravel applications often benefit from query analysis, Redis caching and proper indexing.
php artisan optimize
php artisan config:cache
php artisan route:cache
php artisan view:cache- ✓ Index Foreign Keys
- ✓ Avoid N+1 Queries
- ✓ Use Eager Loading
- ✓ Monitor Slow Queries
Magento MySQL Optimization
Magento is database intensive and benefits significantly from proper MySQL tuning.
- ✓ Increase Buffer Pool Size
- ✓ Enable Redis Cache
- ✓ Use Elasticsearch/OpenSearch
- ✓ Optimize Catalog Indexes
- ✓ Monitor Temporary Tables
- ✓ Tune InnoDB Log Files
Example High Performance MySQL 8 Configuration
[mysqld]
skip-name-resolve
max_connections = 200
innodb_buffer_pool_size = 12G
innodb_log_file_size = 1G
innodb_log_buffer_size = 64M
innodb_flush_method = O_DIRECT
tmp_table_size = 256M
max_heap_table_size = 256M
table_open_cache = 4000
thread_cache_size = 100
performance_schema = ON
slow_query_log = ON
long_query_time = 1Frequently Asked Questions
Is MySQLTuner safe to run?
Yes. MySQLTuner is a read-only analysis tool and does not modify your database configuration.
How often should I run MySQLTuner?
Monthly for stable systems and after major application changes or traffic increases.
Should I apply all recommendations?
No. Always review recommendations carefully and test changes before applying them in production.
What is the most important setting?
In most environments, the InnoDB Buffer Pool Size has the biggest impact on performance.
Can MySQLTuner fix slow queries?
No. It identifies issues, but slow queries usually require indexing and query optimization.
Related Articles
Need Help Optimizing MySQL?
CloudRevol helps businesses optimize MySQL, MariaDB, PostgreSQL and Redis environments. Our engineers analyze slow queries, improve database performance, tune memory usage and implement production-ready monitoring.

