WordPress MySQL Tuning: Optimizing Database Performance

How to tune MySQL and MariaDB for WordPress performance, covering configuration optimization, query analysis, and server-level database tuning.

The database is often the bottleneck for high-traffic WordPress sites. While caching reduces database load, dynamic content, admin operations, and logged-in user requests still hit the database directly. MySQL or MariaDB configuration tuning can significantly improve database performance without requiring hardware upgrades.

This guide covers how to tune MySQL and MariaDB for WordPress performance.

InnoDB Configuration

InnoDB is the default and recommended storage engine for WordPress. The most important InnoDB setting is innodb_buffer_pool_size. Set this to 70-80% of your available RAM on a dedicated database server. For shared servers, start with 1-2GB. This setting determines how much data and indexes are cached in memory and has the single biggest impact on database performance.

Configure innodb_log_file_size to 1GB or more for write-heavy WordPress sites. Set innodb_flush_log_at_trx_commit to 2 for better performance with minimal durability risk.

Query Cache

The MySQL query cache stores the results of SELECT queries so identical queries return results from memory. However, the query cache can be a performance bottleneck on write-heavy sites because it must be invalidated whenever data changes. For most WordPress sites, disable the query cache and rely on the WordPress Transients API and object cache instead.

Set query_cache_type to 0 and query_cache_size to 0 to disable the query cache completely. This is the recommended setting for MySQL 8.0+ which has deprecated the query cache.

Connection Limits

WordPress sites with high traffic can exhaust database connections. Configure max_connections to handle peak traffic. A typical VPS can handle 150-300 connections. Monitor connection usage with SHOW STATUS LIKE ‘Threads_connected’. Increase max_connections if you see connection errors in your logs.

Use persistent connections with caution. They can help performance but may cause issues with some WordPress plugins.

Slow Query Log

Enable the MySQL slow query log to identify problematic queries. Set long_query_time to 1 second or less. Queries that take longer than this are logged for analysis. Review the slow query log regularly to identify queries that need optimization — missing indexes, full table scans, or inefficient JOIN operations.

Use the mysqldumpslow tool to summarize slow query log data. Focus optimization efforts on the most frequently occurring slow queries.

Table Optimization

Regular table maintenance improves performance. Run OPTIMIZE TABLE on WordPress tables monthly to defragment them. Run ANALYZE TABLE to update index statistics for the query optimizer. Use CHECK TABLE to detect corruption. Schedule these operations during low-traffic periods using cron jobs.

For large tables (wp_postmeta, wp_options), consider archiving old data or splitting tables to improve query performance.

The Bottom Line

MySQL tuning can dramatically improve WordPress database performance. Configure InnoDB buffer pool size appropriately, disable the query cache, set connection limits for your traffic, enable the slow query log to identify problems, and perform regular table maintenance. Combined with object caching and query optimization, these settings keep your database running efficiently.

Leave a Reply

Your email address will not be published. Required fields are marked *