mySQL table and DB sizes in
A colleague today asked me about size of a specific database on a dedicated database server for a shared hosting platform. So, in the spirit of sharing – I answered his question, wrote it down, and passed it on. Dull, obvious, but hey, aide mémoire for the win.
ALL DATABASES SIZES
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;
SIZE OF A SPECIFIC DATABASE
SELECT sum(round(((data_length + index_length) / 1024 / 1024 / 1024), 2)) as “Size in GB” FROM information_schema.TABLES WHERE table_schema = “your_database_name“
SIZE OF TABLES WITHIN A GIVEN DATABASE
SELECT table_name AS “Table”, ROUND(((data_length + index_length) / 1024 / 1024), 2) AS “Size (MB)” FROM information_schema.TABLES WHERE table_schema = “your_database_name” ORDER BY (data_length + index_length) DESC;