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

下载

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值