There may be situations when you need to calculate MySQL DB disk space usage. Maybe you want to move your server to new one or just utilizing too much HDD space because of something.
This SQL command will show you total HDD space occupied in MB:
1 2 3 |
SELECT SUM(size) as "size in MB" FROM (SELECT table_schema, sum( data_length + index_length ) / 1024 / 1024 as "size" FROM information_schema.TABLES GROUP BY table_schema) x |
If you want to see space occupied by every single database you can use the following SQL query. This will sort databases by disk usage.
1 2 3 4 |
SELECT table_schema,size as "size in MB" FROM (SELECT table_schema, sum( data_length + index_length ) /1024 /1024 as "size" FROM information_schema.TABLES GROUP BY table_schema) as x ORDER BY size DESC |