I have seen the desire for a smaller ibdata file come up lately on the forums.mysql.com
The innodb database uses the ibdata file(s) to store the database data to disk. Configuring your system correctly is key and you can learn more about such options here: http://dev.mysql.com/doc/refman/5.6/en/innodb-configuration.html
InnoDB provides an ACID compliant and transaction safe storage engine; it is very productive but if you are deleting and/or replacing data often, you will need to recover the lost space over time. How much time is dependent on your system and use. You cannot run a single command and recover space in an ibdata file. It will take a few steps and it is not a behind the scenes job, unless done on a slave server. If you have a slave it is best to do this work on the slaved database first then plan to rotate that database server to become the master database.
So two different situations; these are not the only solutions but some solutions :
- You want to keep the ibdata file the same size but you want to just clear out the wasted space
- Backup the database
mysqldump --user=<username> --password=<> --add-drop-database --master-data=2 --triggers --routines --events --databases (list database names and do not add mysql to this list) > /Just_AN_example/mysqldump_<DATEHERE>_.sql
- This gives you an ASCII copy just in case of binary corruption.
- It also has master data via a comment if needed.
- This will keep your mysql authentication in tact as well.
- I would save the mysql database as a dump separately.
- You also can create a backup with MySQL Enterprise Backup or Percona XtraBackup, if the system was a bigger db and needed online backups these are good choices. Up to you which you use for various reasons.
- Checksum your database.
- Gather some numbers on what you have so you can compare it when you load it back.
- This can be done with Percona Toolkit
# ./pt-table-checksum --password=<Password> > checksum_before_dump.txt
- A query you can write yourself.
- I have a blog post on this as well
- Stop/Start the database and take advantage of this downtime for any read only variables you would like to adjust
- Load the database back
- You want to move to innodb_file_per_table and shrink the ibdata file
- Follow steps 1 through 2 in the process listed above.
- In the step 4 of the above process you will want to add the following to your my.cnf file.
- Remove the ibdata file and logs.
- No coming back from this point
- Start the database
- Confirm it is up and running
- Load the database from backup.
This of course would be best to do on a non production/slave server so you can confirm all the steps and get yourself to a workable situation then rotate the slave to be the new master.