Get size of all databases and tables in MySQL

Code first:

SELECT table_schema AS 'Database', 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' 
FROM information_schema.TABLES 
GROUP BY table_schema
ORDER BY 2 desc

This simple SQL query will return the size of all databases of your MySQL Server, listing the largest databases first. This can be useful when figuring out which databases take up most of the space and must be moved to another server. You can execute this query using phpMyAdmin, Navicat, HeidiSQL, or similar software. It may take a bit of time to return the results.

Here is a sample query and its results:

admin

admin

Leave a Reply

Your email address will not be published.