一、问题提出
在mysql中使用独享表空间,启用innodb_file_per_table,把A库表a迁移导入B库,怎么样导入?
二、问题分析
把A库表a迁移导入B库,可以用mysqldump,当然也可以拷贝表a.ibd文件。拷贝表a.ibd文件要有正确的顺序,否则,会有各种错误。
三、操作步骤
正确的操作步骤应该是:在B库,定义表-->删除表空间(alter table ... discard tablespace;)-->拷贝*.ibd/*.cfg文件-->导入表空间(ALTER TABLE ... IMPORT TABLESPACE )
四、不按照定义表-->删除表空间-->拷贝*.ibd/*.cfg文件-->导入表空间,会出现哪些错误呢?
请看如下操作:(1)直接拷贝a.ibd,a.frm到B库的相应位置,报错:
mysql> select * from a;
ERROR 1146 (42S02): Table 'test.a' doesn't exist
mysql> drop table a;
ERROR 1051 (42S02): Unknown table 'test.a'
mysql> create table a (id int,name varchar(30),age int);
ERROR 1813 (HY000): Tablespace for table '`test`.`a`' exists. Please DISCARD the tablespace before IMPORT. #不能创建表a
mysql> #######delete a.ibd a.frm ###### 这里我删除掉 a.ibd a.frm
mysql> select * from a;
ERROR 1146 (42S02): Table 'test.a' doesn't exist
mysql> drop table a;
ERROR 1051 (42S02): Unknown table 'test.a'
mysql> create table a (id int,name varchar(30),age int); ###能创建表a
Query OK, 0 rows affected (0.01 sec)
上面顺序,不能创建表a,不能执行alter table a discard tablespace;
经典的1146错误,表空间遭到破坏,需要进行表空间的恢复。
五、问题总结:
要按照顺序,正确操作。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30393770/viewspace-2123734/
,如需转载,请注明出处,否则将追究法律责任。