Skip to content

Instantly share code, notes, and snippets.

@dustincurrie
Created March 30, 2011 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustincurrie/895383 to your computer and use it in GitHub Desktop.
Save dustincurrie/895383 to your computer and use it in GitHub Desktop.
Calculate size of all MySQL databases
SELECT s.schema_name, CONCAT(IFNULL(ROUND(SUM(t.data_length)/1024/1024,2),0.00),"Mb") as Data_size,
CONCAT(IFNULL(ROUND(SUM(t.index_length)/1024/1024,2),0.00),"Mb") as Index_size,COUNT(table_name) total_tables
FROM INFORMATION_SCHEMA.SCHEMATA s
LEFT JOIN INFORMATION_SCHEMA.TABLES t ON s.schema_name = t.table_schema
WHERE s.schema_name not in("mysql","information_schema","test") GROUP BY s.schema_name order by Data_size DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment