Transportable Tablespaces

迁移File-Per-Table Tablespaces

Transportable Tablespace示例
Transportable Tablespace Internals
本节介绍如何将file-per-table tablespace从一个server迁移到另一个server,也称为可Transportable Tablespaces功能。 在MySQL 5.7.4之前,只支持非分区的InnoDB表。 从MySQL 5.7.4开始,还支持分区的InnoDB表和各个InnoDB表分区和子分区。

There are many reasons why you might copy an InnoDB file-per-table tablespace to a different database server:

  • 生成报告而不影响生产库
  • 为备库初始化数据
  • 用于数据恢复
  • 相对于mysqldump,传输表空间有个更快的速度
  • 将每个文件的表空间移动到具有更适合系统要求的存储介质的服务器.例如,您可能希望在SSD设备上拥有繁忙的表,或在大容量HDD设备上使用大型表.

限制和使用注意事项

  • 仅当innodb_file_per_table设置为ON(这是MySQL 5.6.6的默认设置)时,传输表空间功能才可以使用。 驻留在共享系统表空间中的表不能使用此功能。
  • 在传输过程中,只有只读操作可以执行
  • page size要相同.When importing a tablespace, the page size must match the page size of the importing instance.
  • Prior to MySQL 5.7.4, DISCARD TABLESPACE is not supported for partitioned tables meaning that transportable tablespaces is also unsupported. If you run ALTER TABLE … DISCARD TABLESPACE on 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 TABLESPACE is supported for partitioned InnoDB tables, and ALTER TABLE … DISCARD PARTITION … TABLESPACE is supported for InnoDB table partitions.
  • 当foreign_key_checks设置为1时,对于父 - 子(主键 - 外键)关系的表空间不支持DISCARD TABLESPACE。在放弃父子表的表空间之前,请设置foreign_key_checks = 0。 分区的InnoDB表不支持外键。
  • ALTER TABLE … IMPORT TABLESPACE不会对导入的数据实施外键约束。 如果表之间存在外键约束,则应在相同(逻辑)时间点导出所有表。 分区的InnoDB表不支持外键。
  • ALTER TABLE … IMPORT TABLESPACE和ALTER TABLE … IMPORT PARTITION … TABLESPACE不需要.cfg元数据文件来导入表空间。 但是,在不使用.cfg文件导入时,不会执行元数据检查,并且将发出类似于以下内容的警告:

    1
    2
    3
    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)

    没有.cfg文件导入的能力可能更方便,当不需要模式不匹配。 此外,无法使用.cfg文件导入的能力在无法从.ibd文件收集元数据的崩溃恢复方案中很有用。

    The ability to import without a .cfg file may be more convenient when no schema mismatches are expected. Additionally, the ability to import without a .cfg file could be useful in crash recovery scenarios in which metadata cannot be collected from an .ibd file.

  • 由于.cfg元数据文件限制,在为分区表导入表空间文件时,不会报告分区类型或分区定义差异的模式不匹配。但会报告列差异。

  • 在子分区表上运行ALTER TABLE … DISCARD PARTITION … TABLESPACE和ALTER TABLE … IMPORT PARTITION … TABLESPACE时,允许使用分区表和子分区表名。指定分区名称时,该分区的子分区将包括在操作中。

  • 在MySQL 5.6或更高版本中,如果两个服务器都具有GA(通用可用性)状态并且它们的版本在同一系列中,则从另一个服务器导入表空间文件是有效的。否则,该文件必须在导入它的服务器上创建。

  • 在复制方案中,在主节点和从节点上必须将innodb_file_per_table设置为ON。

  • 在Windows上,InnoDB以小写形式内部存储数据库,表空间和表名。要避免区分大小写操作系统(如Linux和UNIX)上的导入问题,请使用小写名称创建所有数据库,表空间和表。一种方便的方法是在创建数据库,表空间或表之前,在my.cnf或my.ini文件的[mysqld]节中添加以下行:

    1
    2
    [mysqld]
    lower_case_table_names=1
  • ALTER TABLE … DISCARD TABLESPACE和ALTER TABLE … IMPORT TABLESPACE不支持general tablespace
  • 从MySQL 5.7.9开始,InnoDB表的默认行格式可以使用innodb_default_row_format配置选项配置。如果源服务器上的innodb_default_row_format设置与目标服务器上的设置不同,则试图导入未明确定义行格式(ROW_FORMAT)或使用ROW_FORMAT = DEFAULT的表可能会导致模式不匹配错误。有关相关信息,请参见第15.11.2节“指定表的行格式”。

innodb_default_row_format
The innodb_default_row_format option, introduced in MySQL 5.7.9, defines the default row format for InnoDB tables (including user-created InnoDB temporary tables). The default setting is DYNAMIC. Other permitted values are COMPACT and REDUNDANT. The COMPRESSED row format, which is not supported for use in the system tablespace, cannot be defined as the default.

Newly created tables use the row format defined by innodb_default_row_format when a ROW_FORMAT option is not specified explicitly or when ROW_FORMAT=DEFAULT is used.

When a ROW_FORMAT option is not specified explicitly or when ROW_FORMAT=DEFAULT is used, any operation that rebuilds a table also silently changes the row format of the table to the format defined by innodb_default_row_format. For more information, see Section 15.11.2, “Specifying the Row Format for a Table”.

Internal InnoDB temporary tables created by the server to process queries use the DYNAMIC row format, regardless of the innodb_default_row_format setting.

In MySQL 5.7.8 and earlier, the default row format is COMPACT.
REDUNDANT和COMPACT行格式支持最大索引关键字前缀长度为767字节,而DYNAMIC和COMPRESSED行格式支持索引关键字前缀长度为3072字节,如果innodb_large_prefix配置选项启用。 在复制环境中,如果innodb_default_row_format在主服务器上设置为DYNAMIC,并在从服务器上设置为COMPACT,则以下没有显式定义行格式的DDL语句在主服务器上成功,但在从服务器上失败:
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 VARCHAR(5000), KEY i1(c2(3070)));
要查看表的行格式,请发出SHOW TABLE STATUS语句或查询INFORMATION_SCHEMA.TABLES。
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'test/t1' \G

  • 当导出使用InnoDB表空间加密功能加密的表空间时,InnoDB除了生成.cfg元数据文件外还会生成.cfp文件。在目标服务器上执行ALTER TABLE … IMPORT TABLESPACE操作之前,必须将.cfp文件与.cfg文件和表空间文件一起复制到目标服务器。 .cfp文件包含传输密钥和加密的表空间密钥。在导入时,InnoDB使用传输密钥来解密表空间密钥。有关相关信息,请参见第15.7.10节“InnoDB表空间加密”。

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2022 Fan() All Rights Reserved.

访客数 : | 访问量 :