One of our  LAMP test servers recently crashed and luckily we were able to salvage the hard disk drive from that server.  Restoring the PHP web files from that box was easy, as you can imagine.  We struggled to restore the databases though because we didn’t have export files like we were used to.  Keep in mind that your database server version should be the same.  If you’re on Ubuntu 12.04 and have kept up to date with both systems, the version numbers should match up.

Here are the steps for restoring an InnoDB MySQL Database on Ubuntu 12.04:

  1. Shut down the mysql service (sudo service mysql stop)
  2. Copy the database folder that contains the .frm files to /var/lib/mysql/[DBNAME].  As far as I know, this folder must be the same name as the old database.
  3. Copy the ibdata1 file from your old server to /var/lib/mysql/ibdata1
  4. ***THIS IS IMPORTANT.  I was hung up for a while on this step.  Make sure the permissions of the files are correct.  Since my server was a throwaway virtual machine for restoring this database, I simply did sudo chmod -R 777 /var/lib/mysql.  This is not recommended if your server is a production server.
  5. Start the mysql service (sudo service mysql start)

That’s it.  Your database should be restored. I was really hung up on step #4 until I looked in the log file.  If your service does not start for any reason, check out the log file at /var/log/mysql/error.log.

Hope this helps someone!

Add Comment

Your email address will not be published. Required fields are marked *

This blog is meant for Corporate Zen employees to write about a variety of topics. Posts may contain information and views not directly related to Corporate Zen!