Use INFORMATION_SCHEMA or SHOW TABLE STATUS to quickly find how much disk space each MySQL table uses.
Query information_schema.tables
because it stores data_length
and index_length
. Summing these columns delivers the total on-disk footprint in bytes, which you can convert to megabytes for readability.
SELECT
table_name,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb
FROM information_schema.tables
WHERE table_schema = 'ecommerce'
AND table_name = 'Orders';
Remove the table_name
filter and order by the calculated column. This reveals the largest space consumers instantly.
SELECT
table_name,
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb
FROM information_schema.tables
WHERE table_schema = 'ecommerce'
ORDER BY total_mb DESC;
SHOW TABLE STATUS
offers the same numbers plus row counts and engine details. Its convenient inside interactive sessions, although it produces slightly more verbose output.
SHOW TABLE STATUS FROM ecommerce LIKE 'Orders';
Aggregate by schema to understand storage at the database level and guide capacity planning.
SELECT
table_schema,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS db_mb
FROM information_schema.tables
GROUP BY table_schema;
Run ANALYZE TABLE
before measuring for up-to-date statistics, exclude temporary tables when summing sizes, and monitor growth with scheduled snapshots.
Yes. The data_free
column reports allocated but unused space within the tables tablespace.
After converting to ROW_FORMAT=COMPRESSED or using OPTIMIZE TABLE, MySQL reclaims space and youll see a lower total_mb
.