MySql–Get the Size of your Database

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).

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.