Restore MySQL Database from ibdata and .frm Files
Last week I was presented with a problem that involved restoring a MySQL database for a client using only the /data folder from an original MySQL installation. The solution turned out to be rather simple, but that didn’t stop me from racking my brain for a few hours. Thus, I thought I’d share my experience in hopes of helping others that may run into this.
*NOTE* The MySQL database I was tasked with restoring was associated with a WordPress installation. My guess is that this is irrelevant, though.
*ALSO NOTE* This article assumes you are comfortable with software solutions such as MAMP and/or XAMPP, as well as phpMyAdmin.
I made the decision early on to solve this problem locally, (I find that working directly from a web server usually just gets me into trouble). I use MAMP on a regular basis and as such have quite a few MySQL databases associated with that installation. Rather than fooling with this at all I opted to use XAMPP on a Windows XP SP2 machine. Either one of these solutions will work, as they essentially provide the same services. I chose to avoid using MAMP on my machine because of everything I have invested into that application, but that doesn’t mean you have to.
The first thing you’ll want to do is install a fresh copy of either MAMP, (Mac only), or XAMPP. Then create an empty database using phpMyAdmin with the same name as your original database, (the one you’re trying to restore). For example, if your previous database was called ‘wordpress,’ in phpMyAdmin, (under the ‘Create new database’ text field), you would enter ‘wordpress.’ This will create a folder named wordpress in /Applications/MAMP/db/mysql if you’re using MAMP, or C:\xampp\mysql if you’re using XAMPP. At this point you’ll want to turn off the MySQL service. Now, copy the contents of, (not the entire folder), your mysql database folder that contains the .frm files to the new location. The next step is to copy the ibdata1 file to the MySQL folder in either XAMPP or MAMP, then start the MySQL service again. Now you should be able to locate your database tables in phpMyAdmin.
At this point, (assuming you don’t want to keep the data locally on your machine), you’ll want to export the database using phpMyAdmin. Be sure to check Add DROP TABLE, choose SQL as the export type, and check the ‘Save as file’ checkbox. The .sql file that will be generated can easily be imported into another instance of phpMyAdmin. The new database doesn’t need to have the same name as the previous database, either. I was unable to use my previous database name because the site I was working on had been moved to a shared hosting server, (where someone had already chosen the name of my previous database), and everything worked fine.
Also keep in mind that this can be accomplished whether or not your server is running phpMyAdmin. There are plenty of alternatives available that will allow you to accomplish the same tasks, and there’s always the command line. The most important step is to simply copy the contents of the /data folder and the ibdata1 file. Hope this helps!
Leave a comment if you have any questions!
It does not help at all. It could have been clearer of the instructions are bulleted format.
THANKS A LOT, THE GOD’S PARTNER
James,
Could you perhaps give me an idea of the trouble you’re running into? This may be helpful for me as I could use that information to improve the post. Thanks.
you ar a genious you saved me
So simple. Great. It’s work
Thanks
Hello there,
I had a huge problem.
I reinstalled the xampp into my server this week.
At the time of reinstalling I backed up the old xampp folder.
But when I start the new xampp control panel and start mysql,
I can’t find the old .frm files.
Please help me.
I am currently a deep deep trouble.
Thanks in advance
I did the steps above, but it only restored my MyIsam tables… The table count next to the DB name is correct, but I don’t see any of the InnoDB tables…. What to do!!?
Wow, you saved my life. By the looks of it a load other people too.
Brilliant.
i only have the frm files is it still posible to do this?
I had a database called “Website” and it said there were all 17 tables in it, but when you click it there were 0 even though all 17 tables were in the directory as .frm.
I did what you instructed to do and the same thing happened as when I started, also, now my mysql server will not start. Any ideas how to get it to start again or why it stopped? Also any ideas why I am having the problem with the database?
Scott,
Can you provide me with a bit more information regarding the problem you’re experiencing? It’s difficult to troubleshoot this type of issue when I don’t know exactly what is happening on your end.
Feel free to contact me via email, just fill out the form at http://everythingisgray.com/contact-me/.
Thank you.
Hi James/Scott
Similar problem here; I tried to restore my frm files for a Magento DB but now all I see is 2 tables despite 327 frm files! …did you find a solution or reason for this?
Worked this out.In an effort to sort another issue we had upgraded MAMP to 2.0 – the frm files from our old MAMP 1.9 weren’t compatible it would seem! Thanks
THanks this advice really help to me
I’m using xampp and for some reason phpmyadmin see that a database has 54 tables when I click on in the database is empty. The frm files are there and that database is able to be add new tables and get vivible. Any Idea to solve this issue? (mac osx) thanks
Cannot thank you enough! Sincerely – Thankyou. I had a dodgy hardrive that had two months worth of work on it and it failed, I managed to recover the mysql file but as I failed to previously backup an sql export file it was proving a real nightmare. Your advice proved to be perfect.
You’re very welcome!
I followed your exact steps to the letter but I am still unable to restart the MySQL service. Any ideas why? I’ve tried both replacing and not replacing the .opt files in the schema folders.
Life saver, thanks!
You’re welcome!