How to optimize MySQL performance
Updated 7/20/2026
A slow database slows down the whole site. A few simple tweaks make a big difference for MySQL.
1. The InnoDB buffer pool
The most important setting: give the buffer pool about 60-70% of the server RAM (if the server is dedicated to the database). In /etc/mysql/mysql.conf.d/mysqld.cnf:
innodb_buffer_pool_size = 2G
2. Find slow queries
Enable the slow query log:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
3. Add indexes
The most common cause of slowness is missing indexes on columns used in WHERE and JOIN. Analyze with:
EXPLAIN SELECT * FROM orders WHERE user_id = 42;
If you see a full table scan, add an index on that column.
4. RAM matters
MySQL benefits enormously from RAM, which keeps frequent data in memory. If your database grows, move to a plan with more RAM; you can resize without reinstalling.
5. Keep the database clean
Periodically run OPTIMIZE TABLE on large tables and delete data you no longer need.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to secure MongoDB with authentication
By default, MongoDB runs without a password. Here is how to enable authentication and create an admin user.
Updated 7/20/2026DatabasesHow to migrate a database between servers
Move a MySQL or PostgreSQL database to a new server with minimal downtime, using dump and restore.
Updated 7/20/2026DatabasesHow to connect an app to a remote database
Allow access to a database from another server, securely: bind address, dedicated user and firewall.
Updated 7/20/2026