Skip to content

Instantly share code, notes, and snippets.

@mkdynamic
Created May 10, 2009 10:59
Show Gist options
  • Save mkdynamic/109588 to your computer and use it in GitHub Desktop.
Save mkdynamic/109588 to your computer and use it in GitHub Desktop.
Shows the sizes of all mysql databases
`which mysql` -u root -p INFORMATION_SCHEMA -e 'SELECT s.schema_name,
CONCAT(IFNULL(ROUND((SUM(t.data_length)
+SUM(t.index_length))/1024/1024,2),0.00),"Mb") total_size,
CONCAT(IFNULL(ROUND(((SUM(t.data_length)+SUM(t.index_length))
-SUM(t.data_free))/1024/1024,2),0.00),"Mb") data_used,
CONCAT(IFNULL(ROUND(SUM(data_free)/1024/1024,2),0.00),"Mb") data_free,
IFNULL(ROUND((((SUM(t.data_length)+SUM(t.index_length))
-SUM(t.data_free))/((SUM(t.data_length)
+SUM(t.index_length)))*100),2),0) pct_used,
COUNT(table_name) total_tables
FROM INFORMATION_SCHEMA.SCHEMATA s
LEFT JOIN INFORMATION_SCHEMA.TABLES t
ON s.schema_name = t.table_schema
GROUP BY s.schema_name
ORDER BY SUM(t.data_length)+SUM(t.index_length) DESC;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment