14.8 InnoDB File-Format Management

MYSQL5.6官方文档
14.8 InnoDB File-Format Management
PDF下载地址:http://download.csdn.net/detail/paololiu/9586290
中文只是我个人阅读时的理解,歧义的地方请以英文内容为准。


14.8 InnoDB File-Format Management

14.8.1 Enabling File Formats

14.8.2 Verifying File Format Compatibility

14.8.3 Identifying the File Format in Use

14.8.4 Modifying the File Format

As InnoDB evolves, data file formats that are not compatible with prior versions of InnoDB are sometimes required to support new features. To help manage compatibility in upgrade and downgrade situations, and systems that run different versions of MySQL, InnoDB uses named file formats. InnoDB currently supports two named file formats, Antelope and Barracuda.

InnoDB的数据文件格式和以前的版本是不兼容的,因为有的时候需要支持新的特性。为了应对升级时的兼容性问题及回滚的徐哟呵哦,InnoDB可以使用文件格式在不同版本的MySQL里运行。目前InnoDB支持两种文件格式,Antelope and Barracuda。

  • Antelope is the original InnoDB file format, which previously did not have a name. It supports COMPACT and REDUNDANT row formats for InnoDB tables and is the default file format in MySQL 5.6 to ensure maximum compatibility with earlier MySQL versions that do not support the Barracuda file format.

  • Antelope是原始的InnoDB文件格式,支持InnoDB表 COMPACT and REDUNDANT的行格式,也是MySQL5.6默认的文件格式,用来确保和早期MySQL版本的兼容性问题。

  • Barracuda is the newest file format. It supports all InnoDB row formats including the newer COMPRESSED and DYNAMIC row formats. The features associated with COMPRESSED and DYNAMIC row formats include compressed tables, off-page storage for long column data, and index key prefixes up to 3072 bytes (innodb_large_prefix). See Section 14.9, “InnoDB Row Storage and Row Formats”.

  • Barracuda 是最新的文件格式,它支持所有的InnoDB行格式,包括新的COMPRESSED and DYNAMIC。新的特性有COMPRESSED and DYNAMIC行格式的压缩表,用户长列数据的off-page存储,还有索引前缀key可以达到3072 bytes(innodb_large_prefix)。详见Section 14.9, “InnoDB Row Storage and Row Formats”。

This section discusses enabling file formats for new InnoDB tables, verifying compatibility of different file formats between MySQL releases, identifying the file format in use, and downgrading the file format.

这部会告诉你如何为新的InnoDB表开始文件格式,验证不同MySQL版本之间文件格式的兼容性,确认使用的文件格式,以及回退到原来的文件格式。

14.8.1 Enabling File Formats

The innodb_file_format configuration option defines the file format used when InnoDB tables are created in file_per_table tablespaces.

innodb_file_format配置参数定义了InnoDB创建file_per_table表空间时使用的文件格式。

Antelope is the default innodb_file_format.

innodb_file_format.默认的值是Antelope。

To preclude the use of features supported by the Barracuda file that make your database inaccessible to the built-in InnoDB in MySQL 5.1 and prior releases, set innodb_file_format to Antelope. Alternatively, you can disable innodb_file_per_table to have new tables created in the system tablespace. The system tablespace is stored in the original Antelope file format.

因为构建在MySQL5.1及其之前的版本的InnoDB是不支持Barracuda文件格式的,所以为了监控innodb_file_format默认的是Antelope。还有系统表空间使用的也是原始的Antelope文件格式。

You can set the value of innodb_file_format on the command line when you start mysqld, or in the option file (my.cnf on Unix, my.ini on Windows). You can also change it dynamically with a SET GLOBAL statement.

innodb_file_format可以在启动命令行里,配置文件里设定,也可以通过SET GLOBAL动态修改。

mysql> SET GLOBAL innodb_file_format=Barracuda;

Query OK, 0 rows affected (0.00 sec)

Be aware that ALTER TABLE operations that recreate InnoDB tables use the current innodb_file_format setting.

然后再用ALTER TABLE使用当前的innodb_file_format设定来重建InnoDB表。

Although Oracle recommends using the Barracuda format for new tables where practical, in MySQL 5.6 the default file format is Antelope, for maximum compatibility with replication configurations containing earlier MySQL releases.

虽然Oracle公司建议在实际环境中对新表使用Barracuda格式,但是为了在和早期版本配置主从存在的兼容性问题,MySQL 5.6默认的还是Antelope文件格式。

14.8.2 Verifying File Format Compatibility

14.8.2.1 Compatibility Check When InnoDB Is Started

14.8.2.2 Compatibility Check When a Table Is Opened

InnoDB incorporates several checks to guard against the possible crashes and data corruptions that might occur if you run an old release of the MySQL server on InnoDB data files that use a newer file format. These checks take place when the server is started, and when you first access a table. This section describes these checks, how you can control them, and error and warning conditions that might arise.

InnoDB会使用数种检查来防止在老版本MySQL使用新的InnoDB文件格式时发生故障。这些检查会在实例启用,第一次访问表的时候执行。这部分的内容就讲述了如何控制这些检查,以及它们所产生的报错和警告。

Backward Compatibility

You only need to consider backward file format compatibility when using a recent version of InnoDB (MySQL 5.5 and higher with InnoDB) alongside an older version (MySQL 5.1 or earlier, with the built-in InnoDB rather than the InnoDB Plugin). To minimize the chance of compatibility issues, you can standardize on the InnoDB Plugin for all your MySQL 5.1 and earlier database servers.

当你混用新(MySQL 5.5 and higher with InnoDB)老(MySQL 5.1 or earlier, with the built-in InnoDB rather than the InnoDB Plugin)版本MySQL时要注意文件格式的向后兼容性。

In general, a newer version of InnoDB may create a table or index that cannot safely be read or written with an older version of InnoDB without risk of crashes, hangs, wrong results or corruptions. InnoDB includes a mechanism to guard against these conditions, and to help preserve compatibility among database files and versions of InnoDB. This mechanism lets you take advantage of some new features of an InnoDB release (such as performance improvements and bug fixes), and still preserve the option of using your database with a prior version of InnoDB, by preventing accidental use of new features that create downward-incompatible disk files.

一般情况下,新版本的InnoDB能够创建老版本格式的表或索引,而且没有崩溃,hangs,结果错误或者损坏的风险。InnoDB有自己的一套机制来预防这样情况,能够帮你预防不同版本InnoDB之间数据文件的兼容性问题。这种机制能够让你既可以利用InnoDB的一些主要的新特性(例如某些性能的改善和bug的修补),也能够阻止某些特性来保证老版本InnoDB文件格式的兼容性。

If a version of InnoDB supports a particular file format (whether or not that format is the default), you can query and update any table that requires that format or an earlier format. Only the creation of new tables using new features is limited based on the particular file format enabled. Conversely, if a tablespace contains a table or index that uses a file format that is not supported, it cannot be accessed at all, even for read access.

如果一个版本的InnoDB支持某种文件格式(不论是否是默认的格式),那么这种格式以及之前的格式都是可兼容的。只有使用新格式的某些新特性在使用上会有限制。相反,如果表空间使用的文件格式是不支持的,那么它根本就无法进行访问。

The only way to “downgrade” an InnoDB tablespace to the earlier Antelope file format is to copy the data to a new table, in a tablespace that uses the earlier format.

把一个InnoDB表空间降级到早先的Antelope文件格式的唯一方法就是把数据复制到一个使用老版本格式创建的新表里。

The easiest way to determine the file format of an existing InnoDB tablespace is to examine the properties of the table it contains, using the SHOW TABLE STATUS command or querying the table INFORMATION_SCHEMA.TABLES. If the Row_format of the table is reported as ‘Compressed’ or ‘Dynamic’, the tablespace containing the table uses the Barracuda format. Otherwise, it uses the prior InnoDB file format, Antelope.

要确认现有的一个InnoDB表空间的文件格式,可以使用SHOW TABLE STATUS或者查询INFORMATION_SCHEMA.TABLES。如果表的Row_format显示为’Compressed’ or ‘Dynamic’,那么表空间使用的就是Barracuda格式。否则,使用的就是早期的Antelope格式。

Internal Details

Every InnoDB file-per-table tablespace (represented by a *.ibd file) file is labeled with a file format identifier. The system tablespace (represented by the ibdata files) is tagged with the “highest” file format in use in a group of InnoDB database files, and this tag is checked when the files are opened.

每个InnoDBfile-per-table表空间文件(*.ibd file)都是通过文件格式标识来封装的。系统表空间(ibdata files)是通过InnoDB最高的文件格式来打标签的,而且文件打开时会对这个标签进行检查。

Creating a compressed table, or a table with ROW_FORMAT=DYNAMIC, updates the file header of the corresponding file-per-table .ibd file and the table type in the InnoDB data dictionary with the identifier for the Barracuda file format. From that point forward, the table cannot be used with a version of InnoDB that does not support the Barracuda file format. To protect against anomalous behavior, InnoDB performs a compatibility check when the table is opened. (In many cases, the ALTER TABLE statement recreates a table and thus changes its properties. The special case of adding or dropping indexes without rebuilding the table is described in InnoDB Fast Index Creation.)

当创建一个压缩表的时候,或者表使用了ROW_FORMAT=DYNAMIC,InnoDB会更新相关file-per-table .ibd文件的文件头,而且还会在InnoDB数据字典里将其标记为Barracuda文件格式。在那之后,这个表就不能再用在不支持Barracuda 文件格式的环境里。为了防止异常情况,InnoDB的表打开的时候是会要进行兼容性检查的。(在很多情况下,ALTER TABLE会重建表,因此表的属性也能更改,但也还有一种特别的情况是能够在重建表的情况下添加和删除索引。具体信息可以见InnoDB Fast Index Creation)

Definition of ib-file set

To avoid confusion, for the purposes of this discussion we define the term “ib-file set” to mean the set of operating system files that InnoDB manages as a unit. The ib-file set includes the following files:

为了避免混乱,InnoDB定义了一组文件的集合。这个计划包括下面的文件:

  • The system tablespace (one or more ibdata files) that contain internal system information (including internal catalogs and undo information) and may include user data and indexes.

  • 系统表空间(一个或者多个ibdata文件)包含了系统内部信息(包括内部目录和undo信息),以及有可能的用户数据和索引。

  • Zero or more single-table tablespaces (also called “file per table” files, named *.ibd files).

  • 零或多个单表表空间(file_per_table文件,名字*.ibd)。

  • InnoDB log files; usually two, ib_logfile0 and ib_logfile1. Used for crash recovery and in backups.

  • InnoDB日志文件;通常是两个,ib_logfile0 and ib_logfile1,用户故障恢复和备份。

An “ib-file set” does not include the corresponding .frm files that contain metadata about InnoDB tables. The .frm files are created and managed by MySQL, and can sometimes get out of sync with the internal metadata in InnoDB.

“ib-file set”不包括相关的.frm文件,那里只是存储了InnoDB表的元数据。.frm文件是由MySQL创建和管理的,而且有的时候还会避免和InnoDB的内部元数据进行同步。

Multiple tables, even from more than one database, can be stored in a single “ib-file set”. (In MySQL, a “database” is a logical collection of tables, what other systems refer to as a “schema” or “catalog”.)

即使是来自于多个数据库的多个表都可以存储在单个“ib-file set”里。(在MySQL里,“database”是表的一个逻辑集合,其他数据库系统称之为“schema”或者“catalog”。)

14.8.2.1 Compatibility Check When InnoDB Is Started

To prevent possible crashes or data corruptions when InnoDB opens an ib-file set, it checks that it can fully support the file formats in use within the ib-file set. If the system is restarted following a crash, or a “fast shutdown” (i.e., innodb_fast_shutdown is greater than zero), there may be on-disk data structures (such as redo or undo entries, or doublewrite pages) that are in a “too-new” format for the current software. During the recovery process, serious damage can be done to your data files if these data structures are accessed. The startup check of the file format occurs before any recovery process begins, thereby preventing consistency issues with the new tables or startup problems for the MySQL server.

在打开一个ib-file集合的时候为了预防可能的崩溃或者是数据损坏,InnoDB会检查其使用的ib-file集合所支持的所有的文件格式。如果系统在崩溃或者“快速关闭”(也就是说,innodb_fast_shutdown大于零)之后重启,磁盘上的数据结构(例如redo或者undo条目,又或者是doublewrite数据页)对于当前的软件系统来说格式“太新(too-new)”。在恢复的过程中,如果访问这些数据结构会对数据文件造成严重的损坏。所以在处理任何的恢复开始的时候都要检查文件的格式,从而预防一致性的问题。

Beginning with version InnoDB 1.0.1, the system tablespace records an identifier or tag for the “highest” file format used by any table in any of the tablespaces that is part of the ib-file set. Checks against this file format tag are controlled by the configuration parameter innodb_file_format_check, which is ON by default.

从InnoDB1.0.1开始,系统表空间记录了所有的表空间的“最高”的文件格式标识。检查这个文件格式标识是由innodb_file_format_check配置参数控制的,默认就是开启的。

If the file format tag in the system tablespace is newer or higher than the highest version supported by the particular currently executing software and if innodb_file_format_check is ON, the following error is issued when the server is started:

如果表空间里面的文件格式标识比支持的最高的版本还要高而且innodb_file_format_check是开启的,那实例启动的时候就会报下面的错误:

InnoDB: Error: the system tablespace is in a

file format that this version doesn’t support

You can also set innodb_file_format to a file format name. Doing so prevents InnoDB from starting if the current software does not support the file format specified. It also sets the “high water mark” to the value you specify. The ability to set innodb_file_format_check will be useful (with future releases of InnoDB) if you manually “downgrade” all of the tables in an ib-file set (as described in Downgrading the InnoDB Storage Engine). You can then rely on the file format check at startup if you subsequently use an older version of InnoDB to access the ib-file set.

你也还可以设置innodb_file_format,并以此来预防InnoDB启动的时候使用当前不支持的文件格式。当然可以设置成最高的值。如果要手动“下降”所有表的文件格式,那么innodb_file_format_check就会非常有用。

In some limited circumstances, you might want to start the server and use an ib-file set that is in a new file format that is not supported by the software you are using. If you set the configuration parameter innodb_file_format_check to OFF, InnoDB opens the database, but issues this warning message in the error log:

在一些限制的情况下,你可以会想要使用新的,但是当前软件系统不支持的文件格式启动实例。如果innodb_file_format_check配置参数设置成OFF,那么InnoDB能打开数据库,但是会在error日志里产生下面的警告信息:

InnoDB: Warning: the system tablespace is in a

file format that this version doesn’t support

Note

This is a dangerous setting, as it permits the recovery process to run, possibly corrupting your database if the previous shutdown was a crash or “fast shutdown”. You should only set innodb_file_format_check to OFF if you are sure that the previous shutdown was done with innodb_fast_shutdown=0, so that essentially no recovery process occurs.

这是个危险的设定。它会允许恢复操作继续运行,如果之前的关闭是崩溃或者“快速关闭”造成的,那么就可有会发生数据损坏。所以你必须要确认之前的关闭是正常关闭的,本质上不会有恢复操作的时候才能把innodb_file_format_check设置成OFF。

The parameter innodb_file_format_check affects only what happens when a database is opened, not subsequently. Conversely, the parameter innodb_file_format (which enables a specific format) only determines whether or not a new table can be created in the enabled format and has no effect on whether or not a database can be opened.

innodb_file_format_check参数只有在数据库打开的时候有影响。相反,参数innodb_file_format只会决定新表以什么文件格式创建,而对数据库的打开则没有影响。

The file format tag is a “high water mark”, and as such it is increased after the server is started, if a table in a “higher” format is created or an existing table is accessed for read or write (assuming its format is supported). If you access an existing table in a format higher than the format the running software supports, the system tablespace tag is not updated, but table-level compatibility checking applies (and an error is issued), as described in Section 14.8.2.2, “Compatibility Check When a Table Is Opened”. Any time the high water mark is updated, the value of innodb_file_format_check is updated as well, so the command SELECT @@innodb_file_format_check; displays the name of the latest file format known to be used by tables in the currently open ib-file set and supported by the currently executing software.

文件格式的标识是“high water mark”,如果“更高”的格式的表,同样的在实例启动之后这个标识也还会再升高。如果你要访问一个比当前支持的还要高的文件格式的表,那么系统表空间的标识是不会再更新的,但是会发生表级别的兼容性检查,详见Section 14.8.2.2, “Compatibility Check When a Table Is Opened”。任何时候只要“high water mark”更新了,那么innodb_file_format_check的值也会更新。所以可以使用SELECT @@innodb_file_format来显示最近使用的,当前系统支持的文件格式。

14.8.2.2 Compatibility Check When a Table Is Opened

When a table is first accessed, InnoDB (including some releases prior to InnoDB 1.0) checks that the file format of the tablespace in which the table is stored is fully supported. This check prevents crashes or corruptions that would otherwise occur when tables using a “too new” data structure are encountered.

当表第一次访问的时候,InnoDB(包括一些InnoDB1.0之前的版本)会检查表空间的文件格式。当表使用了“太新”的数据结构的时候,这能够预防崩溃或者数据损坏。

All tables using any file format supported by a release can be read or written (assuming the user has sufficient privileges). The setting of the system configuration parameter innodb_file_format can prevent creating a new table that uses a specific file format, even if the file format is supported by a given release. Such a setting might be used to preserve backward compatibility, but it does not prevent accessing any table that uses a supported format.

使用任何支持的文件格式的表都能够进行读写(假设用户有权限)。innodb_file_format系统参数的设定能够预防创建一个特定的文件格式(即使这个文件格式是支持的)。这样的设定可以包含向后的兼容见,但是这不能预防访问任何使用支持的文件格式的表。

Versions of MySQL older than 5.0.21 cannot reliably use database files created by newer versions if a new file format was used when a table was created. To prevent various error conditions or corruptions, InnoDB checks file format compatibility when it opens a file (for example, upon first access to a table). If the currently running version of InnoDB does not support the file format identified by the table type in the InnoDB data dictionary, MySQL reports the following error:

MySQL5.0.21之后的版本不能可靠地使用新版本的数据文件。为了预防这种情况,InnoDB会在打开一个文件的时候会对其的文件格式进行兼容性检查。如果当前的InnoDB不支持这个文件格式,MySQL会报下面的错误:

ERROR 1146 (42S02): Table ‘test.t1’ doesn’t exist

InnoDB also writes a message to the error log:

InnoDB还会在error日志里写入一下信息:

InnoDB: table test/t1: unknown table type 33

The table type should be equal to the tablespace flags, which contains the file format version as discussed in Section 14.8.3, “Identifying the File Format in Use”.

表的类型应该要等于表空间的标识,相关内容可看Section 14.8.3, “Identifying the File Format in Use”。

Versions of InnoDB prior to MySQL 4.1 did not include table format identifiers in the database files, and versions prior to MySQL 5.0.21 did not include a table format compatibility check. Therefore, there is no way to ensure proper operations if a table in a newer file format is used with versions of InnoDB prior to 5.0.21.

InnoDB早期的MySQL4.1之前的版本在数据库文件里是不包括表格式的标识的。MySQL5.0.21之前的版本是没有表格式的兼容性检查的。因此,在5.0.21之前是没办法知道表是否使用了新的文件格式的。

The file format management capability in InnoDB 1.0 and higher (tablespace tagging and run-time checks) allows InnoDB to verify as soon as possible that the running version of software can properly process the tables existing in the database.

InnoDB1.0以及更高版本的文件格式管理(表空间标记以及运行时检查)允许InnoDB尽快核实当前的版本能否正确地处理当前的表。

If you permit InnoDB to open a database containing files in a format it does not support (by setting the parameter innodb_file_format_check to OFF), the table-level checking described in this section still applies.

如果你允许InnoDB打开一个不支持的文件格式的表(innodb_file_format_check配置参数设置成OFF),这一节讲述的表级别的检查仍然适用。

Users are strongly urged not to use database files that contain Barracuda file format tables with releases of InnoDB older than the MySQL 5.1 with the InnoDB Plugin. It may be possible to rebuild such tables to use the Antelope format.

强烈建议不要在MySQL5.1之前的版本(使用InnoDB插件)使用Barracuda文件格式。有可能会重建表而再重新用回Antelope 格式。

14.8.3 Identifying the File Format in Use

If you enable a different file format using the innodb_file_format configuration option, the change only applies to newly created tables. Also, when you create a new table, the tablespace containing the table is tagged with the “earliest” or “simplest” file format that is required to support the table’s features. For example, if you enable the Barracuda file format, and create a new table that does not use the Dynamic or Compressed row format, the new tablespace that contains the table is tagged as using the Antelope file format .

如果使用innodb_file_format配置参数开启了不同的文件格式,那么这个更新只会适用于新创建的表。还有,当你创建了一个新表,表空间的标识为“earliest” or “simplest”来支持表的特性。例如,如果你开启了Barracuda文件格式,而且创建的表没有使用Dynamic or Compressed行格式,那这个新的表空间的标识还是Antelope。

It is easy to identify the file format used by a given table. The table uses the Antelope file format if the row format reported by SHOW TABLE STATUS is either Compact or Redundant. The table uses the Barracuda file format if the row format reported by SHOW TABLE STATUS is either Compressed or Dynamic.

要识别表的文件格式是非常简单的。如果SHOW TABLE STATUS显示的row format是Compact or Redundant,那么表使用的是Antelope 文件格式。如果显示的是Compressed or Dynamic,那么使用的是Barracuda 文件格式。

mysql> SHOW TABLE STATUS\G

*************************** 1. row ***************************

Name: t1

Engine: InnoDB

Version: 10

Row_format: Compact

Rows: 0

Avg_row_length: 0

Data_length: 16384

Max_data_length: 0

Index_length: 16384

Data_free: 0

Auto_increment: 1

Create_time: 2014-11-03 13:32:10

Update_time: NULL

Check_time: NULL

Collation: latin1_swedish_ci

Checksum: NULL

Create_options:

Comment:

You can also identify the file format used by a given table or tablespace using InnoDB INFORMATION_SCHEMA tables. For example:

还可以通过InnoDB INFORMATION_SCHEMA表来识别:

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME=’test/t1’\G

*************************** 1. row ***************************

TABLE_ID: 44

NAME: test/t1

FLAG: 1

N_COLS: 6

SPACE: 30

FILE_FORMAT: Antelope

ROW_FORMAT: Compact

ZIP_PAGE_SIZE: 0

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE NAME=’test/t1’\G

*************************** 1. row ***************************

SPACE: 30

NAME: test/t1

FLAG: 0

FILE_FORMAT: Antelope

ROW_FORMAT: Compact or Redundant

PAGE_SIZE: 16384

ZIP_PAGE_SIZE: 0

14.8.4 Modifying the File Format

Each InnoDB tablespace file (with a name matching *.ibd) is tagged with the file format used to create its table and indexes. The way to modify the file format is to re-create the table and its indexes. The easiest way to recreate a table and its indexes is to use the following command on each table that you want to modify:

每个InnoDB表空间文件(*.ibd)标识的都是表和索引创建的时候的文件格式,所以要修改文件的格式只能重建表和索引。重建表和索引最简单的方式就是用下面的命令:

ALTER TABLE t ROW_FORMAT=format_name;

If you are modifying the file format to downgrade to an older MySQL version, there may be incompatibilities in table storage formats that require additional steps. For information about downgrading to a previous MySQL version, see Section 2.11.2, “Downgrading MySQL”.

如果你哟把文件格式修改降低到MySQL老的版本,因兼容性问题还需要一些其他的步骤。更多的相关信息可以查看Section 2.11.2, “Downgrading MySQL”。

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页