在A服务器上创建数据库uouo123
root(yoon)> show create table uouo123\G
*************************** 1. row ***************************
Table: uouo123
Create Table: CREATE TABLE `uouo123` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
插入数据
root(uouo123)> insert into uouo123 values (1,'HANK');
Query OK, 1 row affected (1.01 sec)
root(uouo123)> insert into uouo123 values (2,'uouo123');
Query OK, 1 row affected (0.04 sec)
root(uouo123)> insert into uouo123 values (3,'GARY');
Query OK, 1 row affected (0.00 sec)
root(uouo123)> insert into uouo123 values (4,'NIKO');
Query OK, 1 row affected (0.02 sec)
root(uouo123)> select * from uouo123;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | uouo123 |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)
在B服务器上,添加参数innodb_force_recovery=1并重启,创建空数据库uouo123,并创建表yoon
mysql> create database uouo123;
use yooQuery OK, 1 row affected (1.01 sec)
mysql> use uouo123;
Database changed
mysql> CREATE TABLE `uouo123` (
-> `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 uouo123 discard tablespace;
Query OK, 0 rows affected (0.02 sec)
将A服务器上的ibd数据文件传输至B服务器上
scp uouo123.ibd 192.168.0.2:/export/data/mysql/data/uouo123
修改权限
chown -R mysql.mysql uouo123.ibd
将表结构和空间建立关系
mysql> alter table uouo123 import tablespace;
Query OK, 0 rows affected, 1 warning (0.04 sec)
查询数据
mysql> select * from uouo123;
+------+------+
| id | name |
+------+------+
| 1 | HANK |
| 2 | uouo123 |
| 3 | GARY |
| 4 | NIKO |
+------+------+
4 rows in set (0.00 sec)