top of page
Untitled (60).png

MySQL Tuning for Faster WordPress Hosting

  • Writer: Missy Ly
    Missy Ly
  • Jan 6
  • 12 min read

Updated: Jan 7

Want a faster WordPress site? Start with your database. MySQL (or MariaDB) powers everything behind the scenes - from loading posts to managing user data. Poor database performance means slower load times, frustrated visitors, and even lower SEO rankings. But with the right tweaks, you can dramatically improve speed, handle more traffic, and reduce server strain.


Key Takeaways:

  • Speed Boost: In one test, tuning MariaDB cut response times from 860ms to 250ms and doubled requests per second.

  • SEO Impact: Faster databases improve Time to First Byte (TTFB), which Google uses as a ranking factor.

  • Cost Savings: Optimized databases use up to 40% less CPU and handle more users without upgrading servers.


Quick Tips:

  • Spot slow queries with tools like Query Monitor or MySQLTuner.

  • Cap post revisions and clean up orphaned metadata to declutter your database.

  • Use caching (e.g., Redis) to reduce database load.

  • Adjust MySQL settings like for better resource use.

  • Regularly clean and optimize database tables for long-term performance.

Bottom line: A well-tuned database is critical for WordPress speed and reliability. Follow these steps to keep your site running smoothly.

MySQL Tuning Performance Impact: Before and After Optimization Results

How to Complete a MySQL Performance Tune (4 Key Tips)


How to Optimize WordPress Database Queries

Every visitor to your WordPress site triggers a flurry of database queries - sometimes dozens or even hundreds. If these queries are slow or redundant, they can drag down your site’s performance. The key to speeding things up is identifying which queries are causing bottlenecks and cutting out unnecessary database calls that waste server resources. Let’s dive into how to pinpoint these issues and fix them.


Finding Slow and Inefficient Queries

Start by using the Query Monitor plugin, a handy tool for spotting problematic queries as they happen. Once installed, you can monitor your site while logged in as an admin. Pay close attention to the "Queries by Component" and "Slow Queries" sections in the admin bar to see which plugins or themes are making inefficient calls.

For a more in-depth analysis, try the MySQLTuner script, which you can run via SSH. This Perl-based tool evaluates your MySQL or MariaDB setup and provides specific recommendations to boost performance and stability. As Major Hayden, the creator of MySQLTuner, explains, it’s designed to "review a MySQL installation quickly and make adjustments to increase performance and stability". To use it, simply run:

This will generate a detailed report, highlighting parameters like and that may need tweaking.

Don’t forget to check the wp_options table, as it can quietly hurt performance. The autoloaded data from this table gets loaded into memory on every page request. Ideally, this data should stay under 1MB; anything over 10MB is a red flag. To measure your autoloaded data, run the following query in phpMyAdmin:

Then, pinpoint the biggest offenders with:


Reducing Unnecessary Database Calls

Once you’ve identified the bottlenecks, the next step is to streamline your database calls. One quick fix is to limit post revisions, which can clutter your table with unnecessary entries over time. To cap revisions at three per post, add this line to your file:

Another way to clean up your database is by removing orphaned metadata. When you delete posts, their associated metadata in the table often sticks around. To find out how many orphaned records you have, run:

If the count is high, you can delete those orphaned records with this query:

Object caching is another powerful technique to reduce database load. Tools like Redis or Memcached store query results in RAM, so WordPress can retrieve data without querying the database every time. In one case study by Moss.sh, an e-commerce site switched to InnoDB and configured Redis for sessions and transients. This change allowed the site to handle double its previous peak traffic without needing additional servers. Another example involved a content-heavy site with 2 million rows in . By adding a composite index on and limiting revisions, they cut average query latency from 180ms to 17ms - a 45% improvement in Time to First Byte.


Adjusting MySQL Server Settings

Once you've cleaned up inefficient queries, it's time to tweak MySQL server settings to give WordPress performance an extra push. The default settings that come with MySQL or MariaDB are pretty basic - they're built for minimal hardware and not for handling the demands of a busy WordPress site. As Jordan Trask, Technology Consultant at Managing WP, explains:

"The stock configuration for MySQL, MariaDB or Percona is untuned... it isn't going to be efficient for your workload in 99% of instances."

Key Configuration Parameters

One critical setting is , which stores data and indexes in RAM. If your server is dedicated to the database, aim to allocate about 70–80% of your available RAM to this. However, if the server also runs PHP and handles web traffic, keep 30–50% of the RAM free for those tasks.

Another important parameter is . Adjust this to fit the traffic your site actually sees. For most WordPress sites, 50–150 concurrent connections are sufficient, which helps to keep memory use under control during traffic surges.

To optimize temporary tables, increase both and to somewhere between 32MB and 64MB. This ensures temporary tables stay in memory rather than being written to disk. For sites with heavy writing activity, set to about 25% of the buffer pool size to improve write performance.

You can apply these adjustments by modifying your MySQL configuration file.


Editing the MySQL Configuration File

The configuration file for MySQL is usually found at or on Linux servers. Before making any changes, back up the file to avoid losing your original settings:

Next, open the file as the root user and add your changes under the section. For example, to set the buffer pool size to 6GB, include the following line:

Once you've made your changes, restart MySQL to apply them:

or

After restarting, check the log file at to ensure everything is running smoothly. If MySQL fails to start, revert to your backup file and carefully review your configuration for any mistakes.


Setting Up Caching Solutions

After fine-tuning your MySQL settings, the next step to lighten the database load is implementing caching. Caching works by storing HTML pages or query results, enabling your server to deliver content without repeatedly running the same database queries. This not only reduces the strain on MySQL but also speeds up your site. Let’s look at some caching methods that work hand-in-hand with your MySQL optimizations.


Installing WordPress Caching Plugins

Page caching is one of the most effective ways to improve your site’s performance. It creates static HTML versions of your pages and serves them directly to visitors, bypassing PHP execution and database queries. Popular plugins like W3 Total Cache and WP Super Cache handle this process seamlessly.

  • W3 Total Cache offers detailed control over various caching layers, including page caching, database caching, and object caching. However, its advanced features come with a steeper learning curve.

  • WP Super Cache, on the other hand, provides a more straightforward setup and works well for most WordPress sites with minimal configuration.

For websites with dynamic content - such as WooCommerce stores or membership platforms - object caching becomes essential. Tools like Redis and Memcached store frequently accessed query results in memory, significantly reducing database load. Instead of querying MySQL repeatedly, data is served straight from memory.

In fact, Redis object caching can cut database load by over 80%. A performance study conducted in July 2023 by Roman Agabekov, Founder of Releem, demonstrated the impact of optimized caching on a WordPress WooCommerce site hosted on an AWS EC2 c5.xlarge instance running MariaDB 10.6. With a tuned configuration that included caching, the average server response time dropped from 860ms to 250ms, queries per second increased by 106%, and CPU usage decreased by 37%.

While application-level caching is highly effective, MySQL query caching may still be an option for older MySQL versions.


Enabling MySQL Query Caching

If your setup uses an older version of MySQL, native query caching can provide some benefits, though it’s less efficient than modern caching solutions. MySQL’s query cache stores the results of statements, allowing identical queries to be served instantly from the cache. However, this feature is deprecated as of MySQL 5.7.20 and completely removed in MySQL 8.0. For MySQL 8.0 or later, you’ll need to rely on tools like Redis, Memcached, or ProxySQL.

For those still running MySQL 5.7 or MariaDB, query caching can be enabled by modifying the file. Add the following lines:

However, it’s important to note that WordPress sites with frequent database writes - such as those with active comment sections or eCommerce transactions - might see worse performance with query caching. This is because any change to a table clears all related cache entries, potentially creating performance bottlenecks.

"It's generally advisable to disable MySQL query cache for WordPress, as caching is better handled by caching plugins or CDNs"

For most WordPress sites, disabling MySQL query caching () and utilizing object caching at the application level will yield better results.


Maintaining Your Database for Better Performance

Beyond query and server tweaks, keeping your database well-maintained is crucial for smooth performance. Over time, WordPress databases tend to collect unnecessary data that can slow down queries and hog memory. Common offenders include post revisions, spam comments, expired transients, and orphaned metadata. Even a modest site with just 100 posts can balloon to over 5,000 rows in the table if revisions pile up unchecked.

Before making any changes to your database, always create a backup. Database modifications can be sensitive, and once changes are made, they’re often irreversible. Once your backup is secure, you’re ready to tackle cleanup and optimization tasks.


Removing Unused Data

One of the most critical areas to address is the table, which holds "autoloaded" data - information WordPress loads on every page request. If this data grows too large, it can significantly slow down your site’s Time to First Byte (TTFB). Ideally, autoloaded data should stay below 800 KB to 1 MB. To find the biggest culprits, you can run this SQL query in phpMyAdmin:

Post revisions are another common source of database clutter. You can limit future revisions by adding a line to your file. To clean up existing revisions, use this SQL command:

Orphaned metadata often lingers when posts or plugins are deleted, leaving behind unnecessary rows in tables like , , and . You can clean these up using an SQL command targeting orphaned metadata.

Expired transients, which are temporary cached data, can also accumulate if not cleared properly after plugins are removed. To delete them, run:

Additionally, you can reduce how long items remain in the trash by adding this line to your file:


Optimizing Database Tables

Once you’ve cleared out redundant data, defragmenting your database tables can further enhance performance. Running the command reorganizes your data and rebuilds indexes, much like defragmenting a hard drive.

"Optimizing a database is akin to defragmenting a hard drive." - Kevin Muldoon, WPMU DEV

To do this, open phpMyAdmin, select your tables, and choose "Optimize table" from the dropdown menu. For a hands-off approach, plugins like WP-Optimize - trusted by over a million users - can automate tasks like clearing spam, trash, and expired transients on a weekly schedule.

Another important step is ensuring all tables use the InnoDB storage engine. InnoDB supports efficient row-level locking, allowing multiple read/write operations simultaneously without locking the entire table. In contrast, MyISAM locks the whole table during writes, which can cause bottlenecks on busy sites. While most modern WordPress installations default to InnoDB, older sites may still have MyISAM tables that need converting.

To keep your database running smoothly, schedule weekly cleanups for transients and spam, monthly table optimizations, and quarterly audits of the autoload size. With a clean and optimized database, you’re ready to move on to monitoring MySQL performance and assessing the impact of your improvements.


Monitoring MySQL Performance

Once you've implemented your database optimizations, it's crucial to monitor the results. Without proper tracking, it's impossible to confirm whether your changes have improved performance.


Using MySQL's Built-In Monitoring Tools

MySQL offers several built-in tools to help you keep an eye on server health and query efficiency in real time. For instance, the SHOW STATUS command provides runtime metrics like the total number of queries executed and table cache misses. Meanwhile, SHOW VARIABLES lets you review configuration settings such as and . You can also use the mysqladmin command-line tool to check server health with commands like and .

Activating the Slow Query Log is another smart move. This log flags queries that take too long to execute, based on a threshold you define. It's a handy way to identify missing indexes or poorly written queries. If you're working with WordPress, the Query Monitor plugin can provide additional insights, such as database query times and the total number of queries, all accessible from your admin toolbar.

For a deeper dive, consider using MySQLTuner.pl, a Perl script designed to analyze your MySQL setup and recommend specific improvements. It evaluates critical metrics like the health of your InnoDB buffer pool and highlights fragmented tables that may need attention. Running this script monthly is a good habit to ensure your configuration keeps pace with your site's growth.

Once you've gathered your server metrics, it's time to evaluate how these changes affect your website's actual performance.


Measuring Website Speed Improvements

Server metrics are only part of the story - tools that measure website speed can show the real-world impact of your optimizations. Start by establishing a baseline using tools like Google PageSpeed Insights, Pingdom, or GTmetrix. These platforms assess key factors like Time to First Byte (TTFB), total page size, and the number of HTTP requests.

Compare your pre-optimization benchmarks with post-optimization results using tools like Google PageSpeed Insights or GTmetrix. For the first month, track these metrics weekly, then switch to monthly monitoring. Pay particular attention to TTFB, as it directly reflects your database's performance. If your TTFB consistently falls within the 200–500ms range and your autoloaded data remains under 1MB, it's a strong indication that your optimizations are delivering the desired results.


Conclusion

Optimizing MySQL isn’t a one-and-done task - it’s an ongoing process that delivers real, measurable improvements. By following the strategies laid out in this guide, you tackle one of the biggest culprits behind sluggish page loads: database inefficiency. As Itamar Haim, a web performance expert, wisely notes:

"You can't build a skyscraper on a shaky foundation"

The impact of proper tuning is undeniable. Take Releem’s research from July 2023, for example: after fine-tuning MariaDB, a content-heavy site with 2 million rows in the table saw its metadata query times plummet from 180 ms to just 17 ms. This change, achieved by adding a composite index and limiting revisions, led to a 45% improvement in Time to First Byte.

Start with the easy wins - like limiting post revisions, cleaning up expired transients, and allocating memory wisely. Pair these with server-level optimizations, such as implementing object caching using Redis or Memcached. But don’t stop there. As your website grows, your optimization efforts need to keep pace. Regular database reviews and consistent tracking of your Time to First Byte ensure your site continues to perform at its best. Even shaving off a single second from load times can make a big difference in conversions and revenue.


FAQs


How can I find and fix slow MySQL queries slowing down my WordPress site?

To tackle slow MySQL queries that might be dragging down your WordPress site's performance, the first step is enabling the slow query log in your MySQL configuration file (usually or ). Set to , choose a log file location (like ), and define a threshold for logging slow queries using (e.g., 1 second). After making these changes, restart MySQL to activate the settings. Then, use your site as usual to allow the system to record any slow queries.

Once you've gathered data, you can review the log file or check the table to pinpoint problematic queries. Pay close attention to entries with the longest execution times. For a summary of performance bottlenecks, tools like MySQLTuner can be incredibly helpful, offering insights and optimization suggestions. If you're unable to enable the slow query log, alternatives like the Performance Schema or commands can help analyze query execution times without requiring disk writes.

After identifying the slow queries, you can work on optimizing them. This might involve adding indexes, cleaning up your table, or rewriting inefficient SQL queries. If you're using WPWorld’s managed WordPress hosting, the process becomes even easier - built-in monitoring tools automatically capture slow-query data, allowing you to focus on fixing the issues without extra hassle.


What are the best ways to optimize MySQL settings for faster WordPress performance?

To get the most out of MySQL for WordPress, start by allocating around 70% of your server's RAM to the InnoDB buffer pool. This ensures that most table data and indexes are stored in memory, cutting down on disk reads and improving performance. If your server uses SSDs, tweak settings like , , and to boost parallel I/O operations.

WordPress often handles a large number of simultaneous requests, so it's important to configure settings to reduce overhead. Set , , and . For InnoDB-specific settings, use and to strike a balance between data durability and performance. If you're running MariaDB or MySQL 5.7, enabling the query cache (, ) can improve performance, though keep in mind that this feature is deprecated in MySQL 8.0.

Maintaining a clean WordPress database is equally important. Regularly clear out unused entries in the table and consider adding indexes to frequently accessed columns, like in the table. Monitoring slow-query logs and optimizing poorly performing queries can also make a big difference. For those using WPWorld’s managed hosting, pre-configured MySQL settings and automated database maintenance are included, ensuring your WordPress site stays efficient and hassle-free.


How does optimizing MySQL improve site speed and SEO for WordPress?

Fine-tuning your MySQL database is key to boosting both your website's speed and its SEO performance. In WordPress, every page request depends on database queries. If your database is overloaded or poorly optimized, it can slow your site down significantly. This can increase your Time-to-First-Byte (TTFB) and page load times - two factors that directly impact user experience and search engine rankings.

Steps like removing unnecessary data (such as outdated revisions), indexing commonly used columns, and ensuring enough RAM is allocated to the InnoDB buffer pool can make a big difference. These tweaks help your database handle queries faster, reduce server CPU strain, and ultimately lead to quicker page loads. The result? Happier users, better engagement, and stronger SEO signals.

If you’re using WPWorld’s managed WordPress hosting, you don’t need to worry about these technical details. MySQL optimization is done automatically, keeping your database efficient and ready to handle growing traffic. This ensures your site stays fast, reliable, and optimized for both visitors and search engines.


Related Blog Posts

 
 
 

Comments


The Only WordPress Hosting

That Grows Your Traffic.

Get included SEO package with your WordPress hosting plan.

Latest Posts

The Only WordPress Hosting

That Grows Your Traffic.

Get included SEO package with your WordPress hosting plan.

The Only WordPress Hosting

That Grows Your Traffic.

Get included SEO package with your WordPress hosting plan.

WPWorld

The only managed WordPress solution that takes care of your site's SEO and provides unlimited scaling resources. 

Get a hosting plan tailored to your specific needs

bottom of page