Table of Contents

Check the size of all MySQL databases

The script below will get the sizes of all databases for a MySQL server. Make sure you “use” a database before you run the script.

CREATE TABLE z_db_size
SELECT TABLE_SCHEMA AS 'database_name', TABLE_NAME AS 'table_name',
((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024) AS size_in_mb
FROM INFORMATION_SCHEMA.TABLES;

Will create temporary table z_db_size

SELECT database_name, SUM(size_in_mb)
FROM z_db_size
GROUP BY database_name
ORDER BY SUM(size_in_mb);

Once report is captured, drop temporary table

DROP TABLE z_db_size;