您的位置:首页 > 数据库 > MySQL

mysql从.frm和.ibd文件恢复数据库

2016-03-21 11:19 471 查看
下载

MySQL Utilities

http://dev.mysql.com/downloads/utilities/

需要安装https://www.microsoft.com/en-us/download/details.aspx?id=40784

1、管理员打开cmd,使用mysqlfrm.exe工具恢复出表的创建语句

mysqlfrm --server=user:pwd@localhost --port=3307 "path_to_.frm_file" > table_name.txt

2、建立同名数据库

3、在数据库下根据之前的建表语句创建表

如果报错11:01:37 ALTER TABLE tbl import TABLESPACE Error Code: 1808. Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.) 0.172 sec

则在建表语句后加上 ROW_FORMAT=COMPACT

4、使用ALTER TABLE table_name DISCARD TABLESPACE;删除新的.ibd文件

5、复制备份的.ibd文件到新建立的表目录下

6、ALTER TABLE table_Name IMPORT TABLESPACE;恢复数据

Download and install the MySQL utilities at -> http://dev.mysql.com/downloads/utilities. Go into your command/terminal to open the MySQL utility, mysqlfrm, and use it to find the structure of your table that you need to restore. How I did that, was I cd'ed into the file location of mysqlfrm, then entered "mysqlfrm --server=user:pwd@localhost
--port=3307 "path_to_.frm_file" > table_name.txt". The .txt file should be saved in the same folder as where your utilities are saved if you didn't specify where you wanted it to go.
In the text file, you'll see the CREATE TABLE statements, that include all the columns and info (basically, the original structure) of your table. Copy that CREATE statement with all that info.
In your MySQL Command, create a new database (CREATE DATABASE database_name). Make it the same name as your original database name.
Create a new table inside the new database--it doesn't have to be the same name as the folder. You can create the new table inside the command prompt, but I created my table in PhpMyAdmin, a free software tool that handles the administration of MySQL over
the web. I simply clicked on the database on PhpMyAdmin, then the SQL table, and pasted the table structure from #3. (As a side note, I always received errors if I named my tables "table" in my command prompt, so try to avoid that name).
On your MySQL Command, go into your database, and enter "ALTER TABLE table_name DISCARD TABLESPACE", which will essentially remove this table's .ibd file.

Copy your original table (the table you want to restore)'s .ibd file into the newly-created table to replace the .ibd file that you just removed. Change your initial .ibd file to the newly created table's name. This will mimic the old .ibd file that you
just deleted. You can find this folder in the MySQL data folder, under the newly-created database folder on your computer.
Go back to your MySQL Command, go into your database, and enter "ALTER TABLE table_Name IMPORT TABLESPACE." You'll receive a "warning" (1) error-type statement, but just ignore that.
And done! if you try to access your new table, it should contain all the data from your old table.

参考
http://dba.stackexchange.com/questions/71596/restoring-mysql-tables-from-ibd-frm-and-mysqllogbin-files
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: