How to size innodb_buffer_pool_size
The single most important MySQL setting: how much memory to give it, how to tell whether it's big enough, and how to change it without a restart.
InnoDB keeps table and index pages it has read in memory, in the buffer pool. When a query needs a page that's already there, it's a memory read. When it isn't, MySQL goes to disk, which is hundreds of times slower. Sizing the buffer pool well is the biggest single performance win in MySQL.
The default is far too small
Out of the box, innodb_buffer_pool_size is 128 MB. That made sense for laptops in 2010. On a server with 16 GB of RAM it means MySQL uses less than 1% of the memory you're paying for.
A good starting point
On a server that runs only MySQL:
| Server RAM | Buffer pool |
|---|---|
| 2–4 GB | 40–50% of RAM |
| 8–16 GB | 60–70% of RAM |
| 32 GB and up | 70–75% of RAM |
Leave room for the operating system, connection buffers (each connection can use several MB for sorts and joins), and anything else on the machine. If your web server or app runs on the same host, size down accordingly.
There's no point making the pool much bigger than your data. Check how much you have:
SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS innodb_gb
FROM information_schema.tables WHERE engine = 'InnoDB';
If your data is 3 GB, a 4–5 GB pool holds all of it with room to grow.
On a dedicated MySQL server you can also set
innodb_dedicated_server=ONand let MySQL size the buffer pool and redo log from the machine's memory. It's a reasonable choice if nothing else runs there.
Is it big enough? Check the miss rate
Two counters tell you how often InnoDB had to go to disk:
SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read%';
Innodb_buffer_pool_read_requests: logical reads (from memory or disk)Innodb_buffer_pool_reads: reads that had to go to disk
The hit rate is 1 - reads / read_requests. On a warmed-up server you want 99% or better. Below that, more memory usually helps, unless the misses come from a few huge scans that will never fit, which is a query problem rather than a memory one.
Changing it without a restart
Since MySQL 5.7 the buffer pool can be resized online:
SET PERSIST innodb_buffer_pool_size = 8 * 1024 * 1024 * 1024;
MySQL resizes in chunks (innodb_buffer_pool_chunk_size, 128 MB by default, times the number of instances), so the final size is rounded up to a multiple of that. Watch progress with:
SHOW STATUS LIKE 'Innodb_buffer_pool_resize_status';
Resize during a quiet period: shrinking in particular can briefly slow things down.
Mistakes to avoid
- Setting it larger than RAM allows. If the server starts swapping or the kernel kills mysqld, everything gets slower, not faster. Watch swap usage after a change.
- Copying a value from another server. Size it for this machine's RAM and this data set.
- Forgetting the other buffers.
max_connections× per-connection buffers can add up. A quick sanity check is that buffer pool plus peak connection memory stays well under total RAM.
SQLNirvana checks the hit rate, your data size and the server's memory every minute, and recommends a size with the reasoning shown. You can try it once, free, with our MySQL health check.