I was able to recover the database folder of MySQL server 5.5 of the corrupted operating system (Windows XP) at
C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.5\data\
How can I manually restore it to the new MySQL Server? When I open the folder, I found out several folders and I believed those are the databases. I didn't file any SQL Files.
Ok, I got the answer to my own problem.
Possible Scenario
- MYSQL program is corrupted and fail to start. Fresh install of MYSQL did not restore the data.
- Computer crashed but hard disk is still working
- Windows corrupted and fail to start up, but data is safe.
For your information, in MYSQL, files with the extension MYD
is the table data, FRM
files is the table definition and MYI
file is the table indices. There is also the ibdata
file specified in the my.ini which is the InnoDB tablesapce files. You have to be an administrator
, so that you can access Document and Settings folder or the Program Files folder.
- Open Window Explorer (Windows Key + E) or Open My Computer and go to the data folder where your database files reside.
- I would recommend you to copy all the folders in the data folder than just picking a few to copy. Copy the database folders and ibdata file (DO NOT COPY THE ib_logfile(x) files!) Note that the ibdata file might not be in the same location as the data files. To find out where it could be, read How to find MYSQL database files in Windows.
- Go over to the target computer, Open System Services. (Type services.msc at the Windows menu “Search Program and files” entry box)
- On the right panel of the Services window, scroll along the list and look for the name “MYSQL“. Select MYSQL and right mouse click and click . Once it has stopped, you will it’s status become blank instead of .
- Similarly look for the location of the data folder. Once you located it, I recommend you back up the folder or just rename it. Paste over the folders and ibdata file you have copied from the source computer to the data folder.
- Go back to the Services window and select back MYSQL. Right mouse click on it and click to resume the MYSQL service.
- Open MYSQL administrator and log on to your database server and you should be able to see your transferred database together with their data.
@JohnWoo's answer is only for MYSIAM
database engine. My answer is strictly for InnoDb storage engine,i.e., FRM
and IBD
files
To recover
InnoDb
database, I followed exactly these steps successfully. Before pointing out the steps, I would like to tell you that I performed the recovery from recovered hard disk of Wndows XP and transferred it to Windows 7. So, this will help both windows xp and windows 7 users. So, the steps which I followed are :-
- The MySQL server at both the machines MUST be stopped. Of course if the OS/hard disk crashed, the server at that machine is already stopped.
- Now, MySQL installation is in 2 folders (for me at least) ->
1. Program Files / Program Files (x86), and
2. C:\Program Data\MySQL in windows 7 and C:\Users\All users\Application Data\MySQL in Windows XP. Note that Program Data(win7) as well as Application Data(WinXP) are hidden folders. - We are ONLY CONCERNED with the MySQL Server ** folder in the Application Data or Program Data folders. The Mysql folder in Program Files is of no use as it does not have your data.
- Now Copy the my.ini file in MySQL Server ** folder.
- Open the data folder and copy these files
1. All the ib_logfile* files
2. All the ibdata* files
3. The database folders (that you want) containing .frm and .ibd files - Now, copy the files mentioned in the above two points in the destination machine. It is highly recommended to take a backup of the replaced files in the destination machine.
- Now, restart the server. If you went right, you would restore your databases without any error.
I would recommend you to have a look at the cold backup method for InnoDB at the mysql docs at dev.mysql.com/doc/mysql-backup-excerpt/5.5/en/innodb-backup.html
I think MySQL's file management is pretty simple by default. Create a simple new database, and copy the recovered files into the mysql subfolder which is created in response, replacing any created database files. If that doesn't work, create a table in the new database to get a hint of what else might be needed.
来源:https://stackoverflow.com/questions/10680261/restore-mysql-database-folder-from-a-recovered-hard-disk