How can you determine how much disk space a particular MySQL table is taking up?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When a MySQL server starts running low on storage, one of the first questions is which table is consuming the space. MySQL exposes table size metadata through information_schema, and that is usually the fastest way to estimate how much room a table and its indexes occupy.
Querying information_schema.TABLES
The standard way to inspect table size is to query information_schema.TABLES. This metadata view includes the size of row data, the size of indexes, and in many cases the amount of free space already allocated.
data_length represents table data, and index_length represents indexes. Adding them together gives a practical estimate of table size.
Interpreting the Main Columns
The numbers are useful, but they are not all measuring the same thing.
- '
data_lengthis the bytes used for rows.' - '
index_lengthis the bytes used for indexes.' - '
data_freeis space allocated but currently unused.'
A second query helps when you suspect fragmentation or churn from many deletes and updates.
If free_mb is large, the table may have internal free pages that can potentially be reorganized.
Finding the Largest Tables in a Schema
Often the real task is not measuring one table in isolation but ranking the largest tables in a database so you know where to investigate.
This is a good first pass for capacity planning, index review, or archive cleanup.
Storage Engine Behavior Matters
The query works across engines, but the interpretation depends on how the table is stored.
For MyISAM, the reported values tend to map more directly to table files on disk. For InnoDB, especially in modern MySQL, the situation is more nuanced. If innodb_file_per_table is enabled, each table usually has its own tablespace file, so the reported size is easier to reason about. If it is disabled, many tables share a larger tablespace, and reclaiming operating system disk space becomes less direct.
You can confirm the engine quickly:
That check matters before running cleanup operations or promising storage savings.
Comparing MySQL Metadata with Filesystem Usage
Sometimes metadata is not enough. You may want to compare MySQL's estimate with what the operating system reports for the database directory. The metadata tells you how much space MySQL attributes to the table, while filesystem tools show what is actually allocated on disk.
A schema total can help bridge those two views:
If the filesystem size is much larger than the schema total, the difference may come from shared tablespaces, redo logs, temporary files, or other engine-managed storage rather than a single oversized table.
What to Do with the Result
Once you identify a large table, the next question is usually why it is large. Possible reasons include long retention windows, wide rows, too many secondary indexes, or a table that keeps deleted space internally. The measurement query does not fix anything by itself, but it gives you a grounded starting point.
Typical follow-up actions include archiving old rows, dropping unused indexes, partitioning large historical data sets, or running maintenance where appropriate.
Common Pitfalls
A common mistake is treating data_length + index_length as an exact operating system reading. It is best treated as a strong estimate from MySQL metadata.
Another issue is ignoring InnoDB configuration. Developers sometimes run maintenance expecting the filesystem to shrink immediately, but shared tablespaces can keep the allocated file size even after rows are removed.
It is also easy to focus only on row count. A table with fewer rows can still be larger than another table if it contains wide text columns, blobs, or many indexes.
Finally, do not forget partitions. A partitioned table may have storage concentrated in a subset of partitions, and a simple top-level view can hide that detail.
Summary
- Use
information_schema.TABLESto estimate the size of a MySQL table. - Add
data_lengthandindex_lengthfor a practical total. - Check
data_freewhen fragmentation or deleted space is relevant. - Confirm the storage engine before interpreting the numbers.
- Compare metadata with filesystem usage when the totals do not seem to match.
- Use the result to guide archiving, index review, and storage optimization work.

