Thursday, December 6, 2012

MySQL database size script

Useful scripts that count MySQL database size or individual tables sizes (taken from: http://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size/): 

Database size:
SELECT table_schema "Data Base Name", SUM( data_length + index_length) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;

Individual tables sizes:
SELECT TABLE_NAME, table_rows, data_length, index_length, round(((data_length + index_length) / 1024 / 1024),2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = "schema_name";

No comments:

Post a Comment