When a VPS disk fills up overnight, MySQL is usually the first suspect. WordPress sites, logs, and old tables grow quietly for months, then one morning the site throws a database error. The fix starts with facts, not guesses. To check MySQL table sizes, run one query against information_schema and you get a ranked list of every table with its data size and index size. From there you can tell in minutes whether the problem is one runaway table, a bloated WordPress install, or something outside the database entirely.
Start With the Disk, Not the Database
Before you open MySQL, confirm the database is actually the problem. A full disk can come from backups, Docker images, or log files that have nothing to do with your tables. Run this on the server:
df -h
du -sh /var/lib/mysql
du -sh /var/log/* 2>/dev/null | sort -rh | head -10
If /var/lib/mysql is only a small slice of the used space, your tables are not the culprit and chasing them wastes time. If it is most of the disk, move on to the queries below. This two-minute check also gives you a baseline, so you can measure whether the cleanup actually freed anything. Make it a habit to monitor VPS disk space before it fills up and crashes MySQL, because a database that runs out of room mid-write can corrupt tables and take the whole site down with it.
Check MySQL Table Sizes With One Query
This is the mysql table size query most VPS owners need. It lists every table in one database, sorted from largest to smallest, with sizes in megabytes:
SELECT
table_name AS `Table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`,
ROUND(data_length / 1024 / 1024, 2) AS `Data (MB)`,
ROUND(index_length / 1024 / 1024, 2) AS `Index (MB)`,
table_rows AS `Rows`
FROM information_schema.TABLES
WHERE table_schema = 'your_database'
ORDER BY (data_length + index_length) DESC;
Replace your_database with your real database name. A read-only MySQL user works fine for this, and it is the safer choice when you are only investigating. The Data column shows the table itself, the Index column shows its indexes, and the total is what the table costs you on disk. A table with a small data size and a huge index size tells a different story from one where the data itself is huge: the first points at too many or oversized indexes, the second at too many rows.
Find the Largest MySQL Tables in Every Database
When you run several sites on one VPS, the guilty database may not be the one you expect. This query ranks the largest MySQL tables across all databases:
SELECT
table_schema AS `Database`,
table_name AS `Table`,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC
LIMIT 20;
Run the same idea at database level if you want the totals first:
SELECT
table_schema AS `Database`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`
FROM information_schema.TABLES
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
The database-level view answers a different question: which site or app owns the disk. That matters, because the fix for a WordPress database full of post revisions is nothing like the fix for a logging database that never deletes old rows. Note that table_rows is an estimate for InnoDB tables, not an exact count. Treat row counts as a rough guide and trust the megabyte figures for sizing decisions.
What the Numbers Actually Mean
A table size report only helps if you read it right. First, data_length includes unused space. A table that once held a million rows and now holds ten thousand can still report a large size, because InnoDB does not hand freed pages back to the operating system by default. The size is real disk usage, but the data may be long gone. Second, indexes cost real space. A table with five indexes on wide text columns can carry an index larger than its data, and dropping an unused index frees disk at once. Third, data_free shows reclaimable space inside a table. If it is large, OPTIMIZE TABLE can shrink the table, but only after a backup and outside peak hours, when you can afford the lock it takes. Reading mysql disk usage this way keeps you from deleting rows that were never the problem.
Common Culprits on a WordPress VPS
WordPress databases have a few tables that grow faster than the rest. wp_posts collects revisions, autosaves, and trashed items. wp_postmeta grows with every plugin that stores settings or logs per post. wp_options bloats when plugins leave behind autoloaded rows, and transients that never expire pile up there too. wp_comments and wp_commentmeta grow with spam that was never purged. If your size query shows wp_postmeta at the top, check which meta_key values hold the most rows before you delete anything, because some belong to plugins you still use. The safe way to work through this is to find and remove unused WordPress database tables safely, checking first whether a table belongs to an active plugin. For the usual revision and transient buildup, the steps in this guide to shrink a bloated WordPress database without installing a plugin cover the exact deletes that are safe, and they work from the command line, which is faster than clicking through a plugin on a server that is already short on disk. Watch wordpress database size over time, not once a year, because a table that grows a little every week is easy to miss until it fills the disk.
Binary Logs and ibdata1: the Hidden Disk Eaters
Sometimes the biggest files in /var/lib/mysql are not tables at all. Binary logs record every change for replication and point-in-time recovery, and on a busy site they can reach gigabytes if nobody purges them. Check them with:
SHOW BINARY LOGS;
SHOW VARIABLES LIKE 'expire_logs_days';
If binary logging is on and you do not use replication, set a short expiry or turn it off in your MySQL config. Never delete binary log files by hand; use PURGE BINARY LOGS BEFORE '2026-11-01 00:00:00'; so MySQL updates its own index. The other classic case is ibdata1, the shared InnoDB tablespace. If your server was set up before innodb_file_per_table became the default, all InnoDB data lives in that one file, and it never shrinks. The table size query still tells you which tables hold the data, but freeing space then means a dump, wipe, and restore with file-per-table enabled, which is a maintenance window job, not a quick delete.
What to Do After You Find the Big Tables
Finding the big table is half the job. What you do next decides whether the site survives the cleanup. Back up first, even if the disk is nearly full: pipe mysqldump to another server or an external drive, not onto the same full disk. Then delete what is genuinely trash: expired transients, spam comments, trashed posts, old revisions, and rows from plugins you removed months ago. Drop indexes you can prove are unused, one at a time, checking query speed after each change. Run OPTIMIZE TABLE on tables with large data_free values, outside peak hours. If a table is large because it holds data you still need, do not delete it. Archive old rows to a separate table or another server first, then delete them from the live table. If the data keeps growing at a steady rate, that is a capacity question, and the honest answer may be a bigger disk, not another round of deletes. For a deeper walkthrough, this guide on how to reduce MySQL disk usage on a small VPS without losing data covers the same decisions with concrete commands.
Keep It From Happening Again
A one-time cleanup buys you weeks. A check that runs on its own buys you peace of mind. Put the database-level size query in a weekly cron job that emails you the top ten tables. Set an alert at 80 percent disk use, not 95, because a database that hits 100 percent stops writing and can leave tables in a bad state. Keep the habit small: five minutes a month, same queries, same note of which tables grew. If you want that alert wired up now, follow the steps to set up disk space alerts on your VPS before it runs out so the next growth spurt reaches you as a message, not as a down site. The next time the disk fills up, you will already know which table to look at first.