基于mysql8.0.19版本验证。
INNODB:
mysql innodb引擎可传输表空间导入可以将整个innodb表整个表数据文件从一个database导入到另一个database,或者从一个server导入到另一个server。在大数据量导出导入时,十分方便。但是方便的同时,也有诸多限制,话又说回来,只要满足了这些限制条件,还是很方便的。先看例子:
1,导入innodb普通表
mysql> create database test;
Query OK, 1 row affected (0.03 sec)
mysql> use test;
Database changed
mysql> create table t(id int not null auto_increment primary key,c1 varchar(20),c2 char(30),c3 text);
Query OK, 0 rows affected (0.12 sec)
mysql> insert into t (c1,c2)values('a','b');
Query OK, 1 row affected (0.04 sec)
mysql> insert into t (c1,c2)values('3308','3308');
Query OK, 1 row affected (0.02 sec)
mysql> create database d_import;
Query OK, 1 row affected (0.02 sec)
mysql> use d_import;
Database changed
mysql> create table t(id int not null auto_increment primary key,c1 varchar(20),c2 char(30),c3 text);
Query OK, 0 rows affected (0.06 sec)
mysql> alter table d_import.t discard tablespace;
Query OK, 0 rows affected (0.03 sec)
mysql> flush table test.t for export;
Query OK, 0 rows affected (0.00 sec)
接着将上一步export生成的cfg和完全刷新的ibd文件copy到d_import数据库目录:
cp test/t.* d_import/
copy完成后解锁:
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
导入:
mysql> alter table t import tablespace;
Query OK, 0 rows affected (0.20 sec)
这样就将表t从test数据库导入到database数据库中。注意这是两个不同database的情况,如果要导入到不同database且不同表名,需要将ibd和cfg文件的前缀表名修改为目标表的表名。然后执行import tablespace。实际业务环境中,多数是在不同server,不同平台之间导出导入,这个操作上还是一致。(