Last active
June 8, 2019 13:44
-
-
Save peterdalle/ef04d2bd6f2b679354c4 to your computer and use it in GitHub Desktop.
Get current MySQL database size in MB
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
-- Group by database (MB). | |
SELECT table_schema 'Database Name', | |
SUM(data_length + index_length ) / 1048576 'Database Size (MB)', | |
SUM(data_free) / 1048576 'Free Space (MB)' | |
FROM information_schema.TABLES | |
GROUP BY table_schema; | |
-- Group by database and table (bytes). | |
SELECT table_schema 'databasename', | |
table_name 'tablename', | |
SUM(data_length) 'datasize', | |
SUM(index_length) 'indexsize', | |
SUM(data_length + index_length) 'totalsize' | |
FROM information_schema.tables | |
GROUP BY table_schema, table_name | |
ORDER BY databasename, tablename; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment