When a WordPress site is slow for logged-in users, in the admin or on WooCommerce checkouts, the database is often where the time goes. Page caching hides database work for anonymous visitors, but everything dynamic still depends on how quickly MariaDB or MySQL can answer queries.
Out of the box, database servers use conservative default settings designed to run on almost any machine. On a dedicated WordPress server, those defaults often leave memory unused while the database reads from disk far more than necessary.
Tuning doesn’t require deep database expertise. A handful of settings make most of the difference, and the most important one takes a minute to change. Here’s how I approach it on servers I manage.
Before you tune: measure
Never tune blind. Before changing anything, gather some information:
- How much memory does the server have, and how much do PHP, Redis and other services need?
- How large is the database? Check total data and index size.
- What’s slow? Use the slow query log and Query Monitor to find the actual problem queries.
Check database size with:
Often, the biggest improvement comes not from server settings but from fixing one bad query, a bloated options table or a plugin running thousands of queries per page. Tuning helps the database work efficiently, but it can’t fix inefficient work.
Where settings live
On Ubuntu and Debian, MariaDB settings are usually in files under /etc/mysql/mariadb.conf.d/, and MySQL settings under /etc/mysql/mysql.conf.d/. Add your tuning in a separate file, like 99-wordpress.cnf, under the [mysqld] section, so it’s easy to find and survives package updates.
After changes, restart the database service and check the error log to make sure it started correctly.
The most important setting: innodb_buffer_pool_size
WordPress tables use the InnoDB storage engine. InnoDB keeps frequently used data and indexes in memory in the buffer pool. If the pool is large enough to hold your working data, most queries are answered from memory instead of disk.
The default is small, often 128 MB. For a database larger than that, InnoDB constantly reads from disk.
How to size it
- On a dedicated database server, a common guideline is around 50 to 70 percent of RAM.
- On a server running WordPress, PHP and the database together, which is typical for small and medium sites, be more modest. Allow enough memory for PHP-FPM workers, Redis and the operating system.
A practical approach: if your total WordPress database size is 600 MB, a buffer pool of 1 GB gives room to grow. There’s little benefit to a buffer pool much larger than your total data and indexes.
Check whether it’s working
The buffer pool hit rate shows how often data is found in memory:
Compare Innodb_buffer_pool_reads, which went to disk, with Innodb_buffer_pool_read_requests, the total. On a well-tuned server, reads from disk are a tiny fraction of requests after the server has been running a while.
InnoDB log files
InnoDB writes changes to redo logs before applying them to data files. Logs that are too small cause frequent flushing and slow down write-heavy workloads, like busy stores processing many orders.
For most WordPress sites, the defaults in recent MariaDB and MySQL versions are reasonable. On write-heavy sites, a larger redo log can help. The setting name differs by version, such as innodb_log_file_size in MariaDB and older MySQL versions, and innodb_redo_log_capacity in newer MySQL versions. Check your version’s documentation before changing it.
Flush behaviour
innodb_flush_log_at_trx_commit controls how often InnoDB flushes logs to disk:
- 1, the default, is the safest: every transaction is flushed to disk.
- 2 flushes to the operating system on each commit and to disk about once per second, which is faster but risks losing about a second of transactions in a power failure or operating system crash.
For stores, keep the default. Losing orders isn’t worth a small speed gain. For content sites on reliable infrastructure, some administrators choose 2 for better write performance, accepting the small risk.
Connections
max_connections limits how many clients can connect at once. Each PHP-FPM worker that queries the database uses a connection. If max_connections is lower than your total PHP workers across all sites, you’ll see “Too many connections” errors under load.
Set it comfortably above the maximum number of PHP workers that might connect simultaneously, but don’t set it absurdly high. Each connection uses memory, and a huge number of simultaneous connections can exhaust memory.
Check peak usage:
Temporary tables
Some WordPress queries, especially complex WooCommerce reports and plugins with GROUP BY or ORDER BY on large result sets, create temporary tables. If they exceed the in-memory limit, they’re written to disk, which is slow.
tmp_table_size and max_heap_table_size control the in-memory limit; the effective limit is the smaller of the two. Check how often temporary tables go to disk:
If Created_tmp_disk_tables is a high proportion of Created_tmp_tables, raising both settings moderately can help. But the better fix is often improving the queries creating large temporary tables.
The query cache
Older MySQL setups often used the query cache. It was removed entirely in MySQL 8.0 and is disabled by default in modern MariaDB versions, because it caused contention on busy servers. For WordPress, a persistent object cache like Redis is a much better way to avoid repeating queries. Leave the query cache off.
Use the slow query log
The slow query log records queries that take longer than a threshold. It’s the best tool for finding real database problems.
A threshold of one second catches serious problems. Lower it, perhaps to 0.5 seconds, during an investigation. Review the log with a summary tool, such as mysqldumpslow or pt-query-digest from Percona Toolkit, which group similar queries and show which cost the most total time.
Common findings on WordPress sites:
- Meta queries on large postmeta tables, from filters and searches.
- Autoloaded options loaded on every request, from plugins storing large data.
- Reporting queries from analytics or WooCommerce reports.
- Unbounded queries that fetch every post or every order.
Fix these at the source, through better plugins, indexes, caching or code changes.
Indexes
WordPress’s default indexes cover common queries, but not everything. Large WooCommerce stores and sites with heavy postmeta use often benefit from additional indexes. Some plugins add well-tested indexes for WordPress tables safely. Before adding indexes manually, confirm the slow query actually benefits by using EXPLAIN:
Indexes speed up reads but add overhead to writes and use storage, so add them deliberately.
Use tuning scripts as a guide
Tools like MySQLTuner analyse a running server’s statistics and suggest changes. They’re useful starting points, especially for spotting obvious problems like a tiny buffer pool. Treat suggestions with judgement; they don’t know your workload or other services. Run them after the server has been up for at least a day, so statistics are meaningful.
Make changes safely
- Change one setting at a time where possible.
- Note the before and after values and the date.
- Restart during a quiet period, because restarting the database briefly interrupts the site.
- After restarting, check the error log and test the site.
- Watch performance and memory over the following days.
Keep your tuning file in version control or your server documentation, so you know what changed and why.
A quick example
On one store I worked on, a 4 GB server was running with the default 128 MB buffer pool against a 1.2 GB database. Raising the pool to 1.5 GB, alongside a Redis object cache, cut average admin page generation time by more than half. No code changed; the data simply stayed in memory.
Measure first, then tune.
Revisit settings as data grows
Databases grow. A buffer pool sized perfectly today may be too small in a year. Check the database size and buffer pool hit rate a couple of times a year and adjust before performance quietly slips.
Frequently asked questions
What’s the single most important database setting for WordPress?
innodb_buffer_pool_size. Making it large enough to hold your working data in memory often gives the biggest improvement.
Should I use MariaDB or MySQL?
Both work well with WordPress. Choose a currently supported version of either, ideally matching what your host or distribution supports well.
Will database tuning fix a slow WordPress site?
It helps when the database is a bottleneck, especially for logged-in users and stores. It won’t fix slow plugins, heavy themes or missing page caching.
How do I know if the database is the bottleneck?
Use Query Monitor to see query times per page, check the slow query log and watch server metrics. If database time is a large share of request time, database work is worth tuning.
Final thoughts
Database tuning for WordPress comes down to a few essentials: size the InnoDB buffer pool to hold your working data, keep durable settings for stores, set connections to match PHP workers, use the slow query log to find real problems and leave the old query cache off in favour of Redis. Measure before and after, change things carefully and fix bad queries at the source. A well-tuned database makes every dynamic page faster.




