需求: 将3306(源端)的test.t100w表迁移到3307(目标端)的test
-
目标数据库3307中创建一个源端结构一致空表(t100w)
mysql> create database test; mysql> use test mysql> CREATE TABLE `t100w` ( `id` int DEFAULT NULL, `num` int DEFAULT NULL, `k1` char(2) DEFAULT NULL, `k2` char(4) DEFAULT NULL, `dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY `idx` (`k1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
目标端删除表空间,保留表结构,删除表空间文件
mysql> alter table t100w discard tablespace;
-
源端锁定需要迁移的表
mysql> flush table t100w with read lock;
-
拷贝ibd文件到目标端目录下
[root@db01 test]# cp -a /data/3306/data/test/t100w.ibd /data/3307/data/test/ [root@db01 test]# pwd /data/3307/data/test [root@db01 test]# ll total 94208 -rw-r----- 1 mysql mysql 96468992 Dec 28 17:38 t100w.ibd
-
目标端导入表空间文件
mysql> alter table t100w import tablespace;
-
释放源端表锁
mysql> unlock tables;