Jump to content



Sign in to follow this  
IBMx345

MySQL如何从.ibd文件恢复数据

Recommended Posts

最简单的只需要4步

1.创建一张表,表结构与原表结构一致:

CREATE TABLE <table_name> ...;

2.删除新建的表空间: 

ALTER TABLE <table_name> DISCARD TABLESPACE;

3.将待恢复的<table_name>.ibd文件copy到目标数据库文件夹下,并修改文件权限:

cp <table_name>.ibd /var/lib/mysql/<database_name>
cd /var/lib/mysql/<database_name>
chown mysql:mysql <table_name>.ibd

4.导入表空间:

ALTER TABLE <table_name> IMPORT TABLESPACE;

也可能出现如下问题:

1.mysql 1808错误:

Error Code: 1808. Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, <table_name>.ibd file has ROW_TYPE_COMPACT row format.)
这是由于mysql 5.6的文件恢复到mysql 5.7版本导致的错误,需要在建表语句后面添加ROW_FORMAT=COMPACT,如下所示:

create table test(id int, name varchar(10)) row_format=compact;

2.mysql 1812错误:

Error Code:1812. Tablespace is missing for table <table_name>
copy的ibd文件没有赋权,请按照第二步执行权限


community-logo-original.png

华酷网:http://www.huacool.cn  &  华酷社区:https://bbs.huacool.cn

Share this post


Link to post
Share on other sites
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...