How to optimize MySQL performance
Updated 11/29/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 install and secure PostgreSQL on Ubuntu
Install the most advanced open-source database and configure it safely: password, scram-sha-256 authentication and controlled access.
Updated 11/29/2026DatabasesHow to install and secure MySQL on Ubuntu
Install MySQL or MariaDB on your VPS and secure it properly: root password, removing test accounts and controlled access.
Updated 11/29/2026DatabasesHow to create a MySQL user and grant privileges
Create dedicated MySQL users per application and grant exactly the privileges needed, step by step.
Updated 11/29/2026