在A服务器上创建数据库yoon
root(yoon)> show create table yoon\G
*************************** 1. row ***************************
Table: yoon
Create Table: CREATE TABLE `yoon` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8

插入数据
root(yoon)> insert into yoon values (1,'HANK');
Query OK, 1 row affected (1.01 sec)

root(yoon)> insert into yoon values (2,'YOON');
Query OK, 1 row affected (0.04 sec)

root(yoon)> insert into yoon values (3,'GARY');
Query OK, 1 row affected (0.00 sec)

root(yoon)> insert into yoon values (4,'NIKO');
Query OK, 1 row affected (0.02 sec)

root(yoon)> select * from yoon;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | YOON |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)

在B服务器上,添加参数innodb_force_recovery=1并重启,创建空数据库yoon,并创建表yoon
mysql> create database yoon;
use yooQuery OK, 1 row affected (1.01 sec)

mysql> use yoon;
Database changed
mysql> CREATE TABLE `yoon` (
-> `id` int(11) DEFAULT NULL,
-> `name` varchar(20) DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.09 sec)

将表结构和空间脱离
mysql> alter table yoon discard tablespace;
Query OK, 0 rows affected (0.02 sec)

将A服务器上的ibd数据文件传输至B服务器上
scp yoon.ibd 182.19.4.7:/export/data/mysql/data/yoon

修改权限
chown -R mysql.mysql yoon.ibd

将表结构和空间建立关系
mysql> alter table yoon import tablespace;
Query OK, 0 rows affected, 1 warning (0.04 sec)

查询数据
mysql> select * from yoon;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | YOON |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)

详细步骤如下:
1、停止mysql服务,添加innodb_force_recovery=1 ,启动mysql服务
2、创建新数据库,创建相同表结构的表(表结构必须相同)
3、执行alter table tb discard tablespace;
4、删除表的ibd文件
5、跨服务器复制表ibd文件
6、修改ibd文件权限,执行alter table tb import tablespace;

05-11 13:26