Clean - Shrink ibdata1

To shrink ibdata1 once and for all you must do the following:

MySQLDump all databases into a SQL text file (call it SQLData.sql)
Example, change directory to the /home directory which may be a partition with more space.
mysqldump -uroot -p --all-databases --extended-insert --add-drop-database --disable-keys --flush-privileges --quick --routines --triggers > all-databases.sql

Drop all databases (except mysql schema) via PHPMyAdmin or shell.

service mysql stop

Add the following lines to /etc/my.cnf

[mysqld]
innodb_file_per_table
innodb_flush_method=O_DIRECT
innodb_log_file_size=1G
innodb_buffer_pool_size=4G

rm -f /var/lib/mysql/ibdata1 /var/lib/mysql/ib_logfile

At this point, there should only be the mysql schema in /var/lib/mysql

service mysql start

This will recreate ibdata1 at 10MB, ib_logfile0 and ib_logfile1 at 1G each

Reload SQLData.sql into mysql

ibdata1 will grow but only contain table metadata

Each InnoDB table will exist outside of ibdata1

Suppose you have an InnoDB table named mydb.mytable. If you go into /var/lib/mysql/mydb, you will see two files representing the table

mytable.frm (Storage Engine Header)
mytable.ibd (Home of Table Data and Table Indexes for mydb.mytable)

ibdata1 will never contain InnoDB data and Indexes anymore.

With the innodb_file_per_table option in /etc/my.cnf, you can run OPTIMIZE TABLE mydb.mytable; and the file /var/lib/mysql/mydb/mytable.ibd will actually shrink.

  • 134 Users Found This Useful

Was this answer helpful?

Related Articles

Strict Standards: Non-static method JLoader::register() should not be called statically in

The error message...  Strict Standards: Non-static method JLoader::register() should not be...

Error 500 - Internal Server Error - PHP

This can be due to several factors. The first thing to check is that the permissions on the file...

InnoDB Error Attempted to open a previously opened tablespace

When receiving the error... "InnoDB: Error: Attempted to open a previously opened tablespace....

Error: SoftException in Application(dot)cpp:303 UID of script is small than min_uid

The error message "Error: SoftException in Application(dot)cpp:303 UID of script is small than...

How to Disable XCache for a Domain

On many of our servers xcache is use as part of the php caching mechanism. If you are...