Database optimization is the work of tuning MySQL or MariaDB so queries return in milliseconds instead of seconds, and on managed hosting most of that work should never touch your keyboard. Your host controls the server memory, the storage layer, the InnoDB settings and the slow query log, which means they own about 80% of your database performance. This guide explains what a good host does behind the scenes, and how to tell whether yours is actually doing it.
What Database Optimization Really Covers
People hear “optimize” and picture a single button. In practice, MySQL and MariaDB performance comes from four separate layers, and a weakness in any one of them shows up as a slow admin dashboard or a checkout that stalls.
- Hardware and OS: NVMe storage, available RAM, I/O scheduler, swappiness, and the open files limit.
- Server configuration: buffer pool sizing, temp table limits, connection limits, log file sizes.
- Schema and indexes: the right storage engine, primary keys, and indexes on the columns your queries filter by.
- Query behaviour: what your themes, plugins and cron jobs actually ask the database to do every second.
Your host is fully responsible for the first two, mostly responsible for monitoring the third, and responsible for warning you about the fourth. If a hosting company only touches layer one, you’re renting a box, not buying a managed platform.
Why WordPress Databases Degrade So Predictably
WordPress schemas are simple, but they grow in awkward ways. The wp_options table is loaded on almost every request, and autoloaded rows there should stay under roughly 800 KB; plugins that dump serialized settings and orphaned transients regularly push that past 5 MB.
Then there’s wp_postmeta, which on a busy WooCommerce store or membership site can hold 20 to 50 rows per post. A site with 40,000 orders can carry several million meta rows, and a query without a supporting index will scan them all. That’s the difference between a 40 ms page and a 4 second one.
Sites built on WooCommerce hosting feel this first, because carts, sessions and order lookups are all uncacheable writes. Publishers on magazine hosting hit it through taxonomy joins on huge archives, and membership sites hit it through per-user permission checks that never see a page cache.
The Server Settings Your Host Should Already Have Tuned
Default MariaDB packages ship conservatively so they’ll boot on a Raspberry Pi. Production configuration looks nothing like that, and these are the values a competent host adjusts per plan rather than leaving at stock.
- innodb_buffer_pool_size: the single biggest lever. On a dedicated database server it belongs around 70 to 80% of RAM; where PHP and MySQL share a node, 25 to 40% is more realistic. The goal is to hold your hot working set in memory so reads never touch disk.
- innodb_log_file_size: commonly 256 MB to 1 GB on write-heavy stores, which cuts checkpoint stalls during traffic bursts.
- max_allowed_packet: 64 MB to 256 MB. Too low and large imports, revisions or serialized options fail with cryptic errors mid-migration.
- tmp_table_size and max_heap_table_size: matched values, often 64 MB, so sorting and GROUP BY work stays in RAM instead of spilling to temporary disk tables.
- Query cache: disabled. It’s deprecated in MariaDB and removed entirely from MySQL 8.0, and on multi-core writes it becomes a contention point rather than a speedup.
Below the database, the OS matters too: mq-deadline or none as the I/O scheduler for NVMe, vm.swappiness at 1 to 10, and an open files limit of 65,535 or higher. MariaDB’s own optimization and tuning documentation walks through the reasoning if you want the primary source.
Query-Level Work: The Part Most Hosts Skip
This is the gap. Plenty of providers will size a buffer pool and call it managed hosting, then stay silent while one badly written plugin fires 900 queries per page load. Real database optimization means someone is reading the slow query log.
We keep slow_query_log enabled with long_query_time set to 1 second, and we review what surfaces. Anything repeat-offending gets an EXPLAIN, and the usual verdict is a missing index or a query that can’t use one because of a leading wildcard LIKE. MySQL’s optimization reference is blunt about it: indexes are the primary tool for making SQL queries run faster.
Three fixes solve the majority of what we find:
- Add a composite index matching the WHERE and ORDER BY columns of the offending query.
- Convert any lingering MyISAM tables to InnoDB for row-level locking and crash recovery.
- Move repeat reads into a persistent object cache, which is why Redis or Memcached often cuts database load 60 to 80% on logged-in traffic.
Maintenance: OPTIMIZE TABLE, Cleanup and Backups
Deleting rows in InnoDB doesn’t shrink the file, it leaves fragmented pages behind. Running OPTIMIZE TABLE in MariaDB rebuilds the table and reclaims that space, which is worth doing after a big cleanup of spam comments, expired transients or old order data.
It also locks the table while it runs, so it belongs in a low-traffic window, not a cron job that fires at noon. A sensible schedule is monthly for tables that churn heavily, quarterly for everything else, and never in the middle of a sale. Hosts that optimize all tables blindly every night are creating outages, not preventing them.
Backups belong in the same conversation. Logical dumps are fine under 5 GB; past that, physical snapshots restore far faster, and the only number that matters is how long a full restore actually takes when tested. Ask your provider for that figure, and check their status page history while you’re at it.
Questions to Ask Before You Trust a Host With Your Data
Use these as a short audit. Vague answers usually mean nobody is watching the database at all.
- What is my innodb_buffer_pool_size, and how was that number chosen?
- Is the slow query log on, and can I see the last 30 days of it?
- Do you offer a persistent object cache, and is it isolated per site?
- Are database backups tested by restore, or just written?
- Do you provide read replicas or a separate database node as traffic grows?
Scaling answers matter as much as tuning ones. Once a site pushes past a few hundred concurrent logged-in users, splitting reads to a replica beats any further config tweak, and that requires a host with real scalability architecture rather than one shared box. The same discipline shows up in how updates and security are handled in 2026, and fast database responses feed straight into how AI engines crawl and cite your content.
Frequently Asked Questions
How to optimize MySQL database performance?
Start with the InnoDB buffer pool, sized to hold your working data set, typically 70 to 80% of RAM on a dedicated database server. After that, index the columns your slowest queries filter on, disable the deprecated query cache, add a persistent object cache, and review the slow query log weekly with long_query_time set to 1 second.
Can MySQL handle 100 million records?
Yes, MySQL and MariaDB routinely run tables of 100 million rows and beyond, well past a terabyte in InnoDB. Performance at that scale depends almost entirely on indexing, partitioning and having enough RAM for the hot pages; a 100 million row table with a correct index still answers a point lookup in single-digit milliseconds.
What are the drawbacks of MariaDB?
The main drawback is drift: since the MySQL 8.0 fork point, features like JSON handling, some data types and replication internals differ enough that direct dumps between the two are no longer guaranteed to import cleanly. Enterprise tooling and some commercial applications also certify against Oracle MySQL first, so MariaDB support can lag by a release or two.
How to optimize SQL query to run faster?
Run EXPLAIN first: if it reports a full table scan on more than a few thousand rows, you need an index on the WHERE and ORDER BY columns. Then select only the columns you need instead of SELECT *, avoid leading wildcard LIKE patterns that defeat indexes, and cache results that don’t change on every request.
Want a database that keeps up with your traffic?
We tune MySQL and MariaDB per plan, keep the slow query log under review, and tell you which plugin is causing the problem instead of just adding RAM. Talk to a WebVibo specialist about a free migration and a look at your current query load.
[…] Related reading: Database Optimization: How Your Host Should Manage MySQL/MariaDB. […]
[…] The Redis eviction documentation is worth ten minutes before you set those limits. Pair it with sane database tuning, which we covered in our guide to how your host should manage MySQL and MariaDB. […]
[…] Move to WooCommerce High Performance Order Storage (HPOS) if you have not already, so orders live in dedicated tables instead of wp_posts and wp_postmeta. Give MySQL or MariaDB enough innodb_buffer_pool_size to hold your working set in memory, typically 4 to 16GB for a mid-size catalogue. If reads are the bottleneck, add a read replica for reporting and admin queries so your merchandising team’s export does not compete with live checkouts. The database layer is where most peak-day incidents actually start. […]
[…] queries that keep your store responsive, so performance and security overlap here. Our write-ups on how your host should manage MySQL and MariaDB and optimizing WooCommerce database tables go deeper on both […]