MySQL provides valuable metadata about databases and tables.
Query to Get Size for a Single Database
Use the SELECT statement to get the size of a single database:
SELECT TABLE_SCHEMA AS `Database`,
ROUND(SUM(DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024, 2) AS `Size (MB)`
FROM information_schema.TABLES
WHERE TABLE_SCHEMA="<database name>";
Get Size for all the Databases
View the size of all databases with the following query:
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 SUM(DATA_LENGTH + INDEX_LENGTH) DESC;