This section describes how to copy
tablespaces from one database server to another, otherwise known
as the Transportable
Tablespaces feature. Prior to MySQL 5.7.4, only
InnoDB tables are supported. As
of MySQL 5.7.4, partitioned
InnoDB tables and
InnoDB table partitions and
subpartitions are also supported.
For information about other
copying methods, see Section 14.5.2, “Moving or Copying InnoDB Tables to Another Machine”.
There are many reasons why you might copy an
tablespace to a different database server:
To run reports without putting extra load on a production server.
To set up identical data for a table on a new slave server.
To restore a backed-up version of a table or partition after a problem or mistake.
As a faster way of moving data around than importing the results of a mysqldump command. The data is available immediately, rather than having to be re-inserted and the indexes rebuilt.
To move a file-per-table tablespace to a server with storage medium that better suits system requirements. For example, you may want to have busy tables on an SSD device, or large tables on a high-capacity HDD device.
The tablespace copy procedure is only possible when
innodb_file_per_tableis set to
ON, which is the default setting as of MySQL 5.6.6. Tables residing in the shared system tablespace cannot be quiesced.
When a table is quiesced, only read-only transactions are allowed on the affected table.
When importing a tablespace, the page size must match the page size of the importing instance.
Prior to MySQL 5.7.4,
DISCARD TABLESPACEis not supported for partitioned tables meaning that transportable tablespaces is also unsupported. If you run
ALTER TABLE ... DISCARD TABLESPACEon a partitioned table, the following error is returned: ERROR 1031 (HY000): Table storage engine for 'part' doesn't have this option. As of MySQL 5.7.4,
ALTER TABLE ... DISCARD TABLESPACEis supported for partitioned
ALTER TABLE ... DISCARD PARTITION ... TABLESPACEis supported for
DISCARD TABLESPACEis not supported for tablespaces with a parent-child (primary key-foreign key) relationship when
foreign_key_checksis set to
1. Before discarding a tablespace for parent-child tables, set
InnoDBtables do not support foreign keys.
ALTER TABLE ... IMPORT TABLESPACEdoes not enforce foreign key constraints on imported data. If there are foreign key constraints between tables, all tables should be exported at the same (logical) point in time. Partitioned
InnoDBtables do not support foreign keys.
ALTER TABLE ... IMPORT TABLESPACEand
ALTER TABLE ... IMPORT PARTITION ... TABLESPACEdo not require a
.cfgmetadata file to import a tablespace. However, metadata checks are not performed when importing without a
.cfgfile, and a warning similar to the following will be issued:
Message: InnoDB: IO Read error: (2, No such file or directory) Error opening '.\ test\t.cfg', will attempt to import without schema verification 1 row in set (0.00 sec)
The ability to import without a
.cfgfile may be more convenient when no schema mismatches are expected. Additionally, the ability to import without a
.cfgfile could be useful in crash recovery scenarios in which metadata cannot be collected from an
Due to a
.cfgmetadata file limitation, schema mismatches are not reported for partition type or partition definition differences when importing tablespace files for partitioned tables. Column differences are reported.
ALTER TABLE ... DISCARD PARTITION ... TABLESPACEand
ALTER TABLE ... IMPORT PARTITION ... TABLESPACEon subpartitioned tables, both partition and subpartition table names are allowed. When a partition name is specified, subpartitions of that partition are included in the operation.
In MySQL 5.6 or later, importing a tablespace file from another server works if both servers have GA (General Availability) status and their versions are within the same series. Otherwise, the file must have been created on the server into which it is imported.
In replication scenarios,
innodb_file_per_tablemust be set to
ONon both the master and slave.
InnoDBstores database, tablespace, and table names internally in lowercase. To avoid import problems on case-sensitive operating systems such as Linux and UNIX, create all databases, tablespaces, and tables using lowercase names. A convenient way to accomplish this is to add the following line to the
[mysqld]section of your
my.inifile before creating databases, tablespaces, or tables:
As of MySQL 5.7.9, the default row format for
InnoDBtables is configurable using the
innodb_default_row_formatconfiguration option. Attempting to import a table that does not explicitly define a row format (
ROW_FORMAT), or that uses
ROW_FORMAT=DEFAULT, could result in a schema mismatch error if the
innodb_default_row_formatsetting on the source server differs from the setting on the destination server. For related information, see Section 14.8.2, “Specifying the Row Format for a Table”.
When exporting a tablespace that is encrypted using the
InnoDBtablespace encryption feature,
.cfpfile in addition to a
.cfgmetadata file. The
.cfpfile must be copied to the destination server together with the
.cfgfile and tablespace file before performing the
ALTER TABLE ... IMPORT TABLESPACEoperation on the destination server. The
.cfpfile contains a transfer key and an encrypted tablespace key. On import,
InnoDBuses the transfer key to decrypt the tablespace key. For related information, see Section 14.4.10, “InnoDB Tablespace Encryption”.