Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the ibdata1 file and how it may affect the performance?

I looked into the ibdata file and it was 128 GB. I took out size of each table and a table was having 5 Million of record and it was showing 90 GB.

I truncated that table since it was not necessary and I viewed the ibdata1 size. Still it is showing 128 GB. Then I took out sizes of each table and sum of then is just 35-38 GB.

How can I get back the 90 GB of space on my Db server. I am using mysql with php on red-hat Linux server.

I guess- if we delete anything on DB it just removes the replication but space allotted to it sill not be deallocated till we do it manually. Is it the way.

like image 801
Manojkumar Avatar asked Dec 19 '12 13:12

Manojkumar


People also ask

What happens if I delete ibdata1?

Save this answer. Show activity on this post. ibdata1 contains InnoDB dictionary which is vitally important for InnoDB. If you delete it any access to a table will fail with Table doesn't exist error.

How do you clean ibdata1?

The ibdata1 file can be shrinked if you delete all databases, remove the files and reload the mysqldump. We can configure MySQL so that each table, including its indexes, is stored as a separate file. It is enabled by default as of version 5.6. 6 of MySQL.

What is the use of ibdata1 file in MySQL?

The file ibdata1 is the system tablespace for the InnoDB infrastructure. You can separate Data and Index Pages from ibdata1 by enabling innodb_file_per_table . This will cause any newly created InnoDB table to store data and index pages in an external .


1 Answers

Once space is consumed by your ibdata file it never goes away. The only way to 'shink' the data file is dump your dbs, drop them all, delete the ibdata file, restart mysql and reload the dump.

If you frequently drop entire tables, you can config innodb to use one data file per table. In this case, when you drop a table, you can delete that table specific ibdata file.

like image 110
Ray Avatar answered Sep 25 '22 16:09

Ray