mysql to restore or transfer data tablespace

mysql backup tools often have mysqldump, mysqlpump (5.7 new features) such as backup tool, where we can try to use table space for delivery

It is: copy data files corresponding to the tablespace + copy engine is innodb cfg files and file ibd

Way of implementation of such requirements

(1 ) requires a separate tablespaces, open innodb_file_per_table parameters; 
( 2 ) when doing export table, the table is read only allowed to write; 
( 3 ) data import and export data page size to be the same; 
( 4) in MySQL 5.7 .4 previous version can not be done on the partition table partition mobility; 
( 5) the use of foreign key table, you need to use compulsory set foreign_key_check = 0 to ignore foreign key, otherwise it does not support the import and export of table space, distribution tables do not support foreign key table import export of space;

 

The following example will be described

Prepare two mysql, source + target, at the same time construction of the table command, we call for a source mysql, mysql a call for the target

create table first(id int,name char(16));

A data source is inserted in the mysql

insert into first values(1,'ni'),(2,'wo'),(3,'ta');

Release in the target table space above mysql

alter table first discard tablespace; # equivalent to delete the file first.ibd, leaving first.frm 
At this point you can operate frm file, for example: rename table, drop table, but can not operate on ibd file, for example: dml
verification result:
select * from first;
ERROR 1814 (HY000): Tablespace has been discarded for table 'first'

 

Guess you like

Origin www.cnblogs.com/mmyy-blog/p/11413955.html