Last active
April 5, 2025 15:49
-
-
Save davidromani/9531321 to your computer and use it in GitHub Desktop.
Get MySQL databases size
This file contains hidden or 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
-- full databases resume | |
SELECT table_schema, sum(data_length + index_length)/1024/1024 AS used_space_mb FROM information_schema.TABLES GROUP BY table_schema; | |
-- single database table sizes | |
SELECT | |
table_schema AS database_name, | |
table_name, | |
ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_size_mb, | |
ROUND(data_length / 1024 / 1024, 2) AS data_size_mb, | |
ROUND(index_length / 1024 / 1024, 2) AS index_size_mb, | |
table_rows | |
FROM information_schema.tables | |
WHERE table_schema = 'your_database_name' | |
ORDER BY total_size_mb DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment