Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate needed disk space for InnoDB databases?

Tags:

mysql

innodb

I have several databases in MySQL with InnoDB engine. All together they have around 30 GB size on filesystem. A couple of days ago, I removed a lot of data from those databases (~10-15 GB) but the used space on filesystem is the same and also reading data_length and index_length from information_schema.TABLES give almost the old size.

I dumped a 3,3 GB database and imported it on my workstation where it takes only 1,1 GB (yes, it is a 1:1 copy). So, how can I calculate the size a InnoDB database needs if I would reimport it in a new system?

like image 228
sw0x2A Avatar asked Dec 09 '10 09:12

sw0x2A


People also ask

How do I find the size of a MySQL database?

To check the sizes of all of your databases, at the mysql> prompt type the following command: Copy SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" FROM information_schema.


2 Answers

Optimize your tables after deleting large amouts of data. http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

like image 90
Mchl Avatar answered Sep 20 '22 03:09

Mchl


InnoDB doesn't free disk space; it's a PITA. Basically, you can free it by dropping the database and restoring it from a backup (as you've noticed by chance) - see here for examples.

So, you can't calculate how big a database will be after you restore a backup. But it will never be bigger than the un-backed up one (because the unbacked up version still has space from any deleted data and the restored backup will not have that space).

This can be worked around to some extent using the file per table option; more details in the first link from this post.

like image 39
El Yobo Avatar answered Sep 21 '22 03:09

El Yobo