MySql–Get the Size of your Database

Posted by Blake on 1/24/2012

Here’s a simple query to get the size of your MySQL database in megabytes. I went ahead and rounded that number to 2 decimal places to make the output a little easier to read:

    SELECT table_schema "Database", 
    ROUND(SUM( data_length + index_length ) / 1024 / 1024, 2) "Size in MB"
    FROM information_schema.TABLES 
    GROUP BY table_schema ; 

My hosting provider (Brinkster) allows for a 250MB database so this is handy for me to quickly see whether I’m pushing it’s limits or not. I’ve offset some of my storage needs into SQL Server Compact databases (where the data is isolated and doesn’t need to be joined up).