Skip to content

Instantly share code, notes, and snippets.

@frosit
Created October 20, 2022 14:41
Show Gist options
  • Save frosit/926b33fd8cb3a4a15736b4d35afe6974 to your computer and use it in GitHub Desktop.
Save frosit/926b33fd8cb3a4a15736b4d35afe6974 to your computer and use it in GitHub Desktop.
db commands
-- get db size
SELECT round(Sum(data_length + index_length) / 1024 / 1024, 1) as "Size in MB" FROM information_schema.TABLES WHERE table_schema = database();
-- get sizes of all dbs
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "MB"
FROM
information_schema.tables
WHERE
table_schema NOT IN (
'information_schema',
'performance_schema',
'mysql'
)
GROUP BY
table_schema
ORDER BY
MB DESC;
-- get sizes of tables in db
SELECT TABLE_NAME AS "Table",
table_rows AS Rows,
round(((data_length + index_length) / 1024 / 1024), 2) AS Size_in_MB
FROM
information_schema.TABLES
WHERE
table_schema = database()
ORDER BY
Size_in_MB DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment