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

MySQL Database (Schema) Sizes

Ranks each schema by total size and table count. Used for capacity tracking and growth analysis.

#database-size#capacity#information_schema
mysql · sql
SELECT table_schema,
       COUNT(*) AS tables,
       ROUND(SUM(data_length)  / 1024 / 1024 / 1024, 2) AS data_gb,
       ROUND(SUM(index_length) / 1024 / 1024 / 1024, 2) AS index_gb,
       ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_gb
FROM information_schema.tables
GROUP BY table_schema
ORDER BY SUM(data_length + index_length) DESC;
Operational Notes & Remediation Guidance

Verify in a staging environment prior to running in production. This is a read-only diagnostic query; it does not acquire exclusive locks.

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.

Engineering Triad: Related Runbooks & Incident Response

Which production incidents and emergency drills execute this script as a diagnosis step?

Runbook Library (63)
Related Alerts & Metrics
M24MySQL Data Disk Free SpaceMySQL