MySQL InnoDB Backup

PHP February 21st, 2008

Consider the scenario:

You had a brain fart and deleted a database that you shouldn’t, but you had the backup of the MySQL directory.

Ok, so all you need to do is copy the files to your current data folder in MySql right!? Wrong!!!!!

Not like MyISAM files, InnoDB holds a special file that contains information for data and indexes (ibdata1) and only copying the files will not work.

The tables will appear under phpMyAdmim but they will have the status “in use” or they will throw an error 1146 the table could not be found (crazy error: you can see the table but can’t get indexes, structure or data).

Nothing is lost, you still can restore the database, but for this you will need a smart trick.

Follow this steps:

- Stop the MySQL server
- Change the datadir under the MySql configuration file to the backup directory
- Be sure that this backup directory has the permission set to 755 and save the previous directory path (you are going to need it)
- Start the MySQL server
- Do a SQL Dump for the database(s) that you want to restore (save it on a file)
- Stop the MySQL Server again
- Change the directory to the original path
- Start the MySQL Server
- Restore the database dump

On some servers the backup directory cannot have the permissions changed to 755, so copy everything of this directory to another and you are good to.

Hope it helps you as much it helped me.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]


Leave a Comment

You must be logged in to post a comment.

blank