1.执行 create table tt like t,创建一个相同表结构的空表;


2.执行 alter table tt discard tablespace,这时候 tt.ibd 文件会被删除;


3.执行 flush table t for export,这时候 db1 目录下会生成一个 t.cfg 文件;


4.在 db1 目录下执行 cp t.cfg tt.cfg; cp t.ibd tt.ibd;这两个命令(这里需要注意的是,拷贝得到的两个文件,MySQL 进程要有读写权限);


5.执行 unlock tables,这时候 t.cfg 文件会被删除;

6.执行 alter table tt import tablespace,将这个 tt.ibd 文件作为表 tt 的新的表空间,由于这个文件的数据内容和 t.ibd 是相同的,所以表 tt 中就有了和表 t 相同的数据。
image.png
7.执行 flush table tt for export; unlock tables;,这时候 tt.cfg 文件会被删除;
网友评论