dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/mysql/#23
Script #23
mysql
Storageread-onlyMin Version: 5.7

List the Largest Tables and Disk Usage in MySQL

Ranks tables by data, index and free space size. Core input for capacity planning and archiving decisions.

#table-size#capacity#information_schema
mysql · sql
SELECT table_schema, table_name, engine, table_rows,
       ROUND(data_length  / 1024 / 1024, 1) AS data_mb,
       ROUND(index_length / 1024 / 1024, 1) AS index_mb,
       ROUND((data_length + index_length) / 1024 / 1024, 1) AS total_mb,
       ROUND(data_free / 1024 / 1024, 1) AS free_mb
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','sys','information_schema','performance_schema')
ORDER BY (data_length + index_length) DESC
LIMIT 25;
Operational Notes & Remediation Guidance

`DATA_FREE` indicates reclaimable space after heavy DELETE operations; reclaim via `OPTIMIZE TABLE` during low-traffic maintenance windows.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 5.7).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.