Last active
August 19, 2020 23:25
-
-
Save krasnuydyx/556ad13fb1febb138635826459564012 to your computer and use it in GitHub Desktop.
List sizes of MySQL databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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