Skip to content

Instantly share code, notes, and snippets.

@hidayat365
Last active July 31, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidayat365/de3dfc2817fccff1cdf555229d1a01c4 to your computer and use it in GitHub Desktop.
Save hidayat365/de3dfc2817fccff1cdf555229d1a01c4 to your computer and use it in GitHub Desktop.
MySQL Database and Table Size Query
SELECT table_schema "DB Name",
Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size (MB)"
FROM information_schema.tables
GROUP BY table_schema;
SELECT table_name
, round(((table_rows) / 1024 / 1024), 2) as "Row Count (mil)"
, round(((data_length) / 1024 / 1024), 2) as "Data Size (MB)"
, round(((index_length) / 1024 / 1024), 2) as "Index Size (MB)"
, round(((data_length + index_length) / 1024 / 1024), 2) as "Table Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "DATABASE_NAME"
ORDER BY round(((data_length + index_length) / 1024 / 1024), 2) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment