Skip to content

Instantly share code, notes, and snippets.

@krasnuydyx
Last active August 19, 2020 23:25
Show Gist options
  • Save krasnuydyx/556ad13fb1febb138635826459564012 to your computer and use it in GitHub Desktop.
Save krasnuydyx/556ad13fb1febb138635826459564012 to your computer and use it in GitHub Desktop.
List sizes of MySQL databases
# Database size
SELECT
table_schema AS "Database name",
SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
# Database and index sizes
SELECT SUM(Data_length)/1024/1024/1024,SUM(Index_length)/1024/1024/1024 FROM information_schema.tables;
# WHERE table_schema = '';
# All tables sizes by length from all dbs
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
# All tables for one database
SELECT table_name ,
round(((data_length + index_length) / 1024 / 1024), 2) as SIZE_MB
FROM information_schema.TABLES
WHERE table_schema = (SELECT DATABASE()) ORDER BY SIZE_MB DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment