Thursday, June 19, 2014

Checkout sizes of MySQL databases

Checkout sizes of MySQL databases

If you are trying to find which databases are actually taking up how much space but only have one huge ibdata1 in your /var/lib/mysql and the directories inside your mysql data directory don't represent the actual database sizes?
Go for this

Run from mysql command prompt with root permission

SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;


Result will be like this.

+--------------------+---------------+
| Database name      | Size (MB)     |
+--------------------+---------------+
| information_schema |    0.00781250 |
| db1               | 1753.67187500 |
| db1_live          | 3458.10937500 |
| db1_rpt_live      |   82.37500000 |
| mysql              |    0.61531639 |
+--------------------+---------------+
5 rows in set (29.33 sec)