13.1.10 ALTER TABLESPACE Statement语句

ALTER [UNDO] TABLESPACE tablespace_name
NDB only:
    {ADD | DROP} DATAFILE 'file_name'
    [INITIAL_SIZE [=] size]
    [WAIT]
InnoDB and NDB:
    [RENAME TO tablespace_name]
InnoDB only:
    [AUTOEXTEND_SIZE [=] 'value']
    [SET {ACTIVE | INACTIVE}]
    [ENCRYPTION [=] {'Y' | 'N'}]
InnoDB and NDB:
    [ENGINE [=] engine_name]
Reserved for future use:
    [ENGINE_ATTRIBUTE [=] 'string']

This statement is used with NDB and InnoDB tablespaces. 此语句用于NDBInnoDB表空间。It can be used to add a new data file to, or to drop a data file from an NDB tablespace. 它可用于向NDB表空间添加新数据文件,或从NDB表空间中删除数据文件。It can also be used to rename an NDB Cluster Disk Data tablespace, rename an InnoDB general tablespace, encrypt an InnoDB general tablespace, or mark an InnoDB undo tablespace as active or inactive.它还可用于重命名NDB群集磁盘数据表空间、重命名InnoDB通用表空间、加密InnoDB通用表空间或将InnoDB撤销表空间标记为活动或非活动。

The UNDO keyword, introduced in MySQL 8.0.14, is used with the SET {ACTIVE | INACTIVE} clause to mark an InnoDB undo tablespace as active or inactive. MySQL 8.0.14中引入的UNDO关键字与SET{ACTIVE | INACTIVE}子句一起使用,将InnoDB撤销表空间标记为激活或失活。For more information, see Section 15.6.3.4, “Undo Tablespaces”.有关更多信息,请参阅第15.6.3.4节,“撤消表空间”

The ADD DATAFILE variant enables you to specify an initial size for an NDB Disk Data tablespace using an INITIAL_SIZE clause, where size is measured in bytes; the default value is 134217728 (128 MB). ADD DATAFILE变量使您能够使用INITIAL_SIZE子句指定NDB磁盘数据表空间的初始大小,其中size以字节为单位;默认值为134217728(128 MB)。You may optionally follow size with a one-letter abbreviation for an order of magnitude, similar to those used in my.cnf. 您可以选择在size后面加一个一个字母的缩写,表示一个数量级,类似于my.cnf中使用的缩写。Generally, this is one of the letters M (megabytes) or G (gigabytes).通常,这是字母M(兆字节)或G(千兆字节)中的一个。

On 32-bit systems, the maximum supported value for INITIAL_SIZE is 4294967296 (4 GB). 在32位系统上,INITIAL_SIZE的最大支持值为4294967296(4 GB)。(Bug #29186)

INITIAL_SIZE is rounded, explicitly, as for CREATE TABLESPACE.INITIAL_SIZE显式地四舍五入,就像CREATE TABLESPACE一样。

Once a data file has been created, its size cannot be changed; however, you can add more data files to an NDB tablespace using additional ALTER TABLESPACE ... ADD DATAFILE statements.创建数据文件后,其大小不能更改;但是,您可以使用额外的ALTER TABLESPACE ... ADD DATAFILE语句向NDB表空间添加更多数据文件。

When ALTER TABLESPACE ... ADD DATAFILE is used with ENGINE = NDB, a data file is created on each Cluster data node, but only one row is generated in the INFORMATION_SCHEMA.FILES table. ALTER TABLESPACE ... ADD DATAFILEENGINE = NDB一起使用,在每个集群数据节点上创建一个数据文件,但在INFORMATION_SCHEMA.FILES表中只生成一行。See the description of this table, as well as Section 23.5.10.1, “NDB Cluster Disk Data Objects”, for more information. 有关更多信息,请参阅此表的说明以及第23.5.10.1节,“NDB群集磁盘数据对象”ADD DATAFILE is not supported with InnoDB tablespaces.InnoDB表空间不支持添加数据文件。

Using DROP DATAFILE with ALTER TABLESPACE drops the data file 'file_name' from an NDB tablespace. DROP DATAFILEALTER TABLESPACE一起使用会从NDB表空间中删除数据文件file_nameYou cannot drop a data file from a tablespace which is in use by any table; in other words, the data file must be empty (no extents used). 不能从任何表正在使用的表空间中删除数据文件;换句话说,数据文件必须为空(不使用扩展数据块)。See Section 23.5.10.1, “NDB Cluster Disk Data Objects”. 请参阅第23.5.10.1节,“NDB群集磁盘数据对象”In addition, any data file to be dropped must previously have been added to the tablespace with CREATE TABLESPACE or ALTER TABLESPACE. 此外,任何要删除的数据文件都必须先前已通过CREATE TABLESPACEALTER TABLESPACE添加到表空间中。DROP DATAFILE is not supported with InnoDB tablespaces.InnoDB表空间不支持DROP DATAFILE

WAIT is parsed but otherwise ignored. WAIT被解析,但在其他方面被忽略。It is intended for future expansion.这是为了将来的扩展。

The ENGINE clause, which specifies the storage engine used by the tablespace, is deprecated; expect it to be removed in a future release. ENGINE子句指定表空间使用的存储引擎,不推荐使用;希望在将来的版本中删除它。The tablespace storage engine is known by the data dictionary, making the ENGINE clause obsolete. 数据字典知道表空间存储引擎,这使得ENGINE子句过时。If the storage engine is specified, it must match the tablespace storage engine defined in the data dictionary. 如果指定了存储引擎,则它必须与数据字典中定义的表空间存储引擎匹配。The only values for engine_name compatible with NDB tablespaces are NDB and NDBCLUSTER.NDB表空间兼容的engine_name的唯一值是NDBNDBCLUSTER

RENAME TO operations are implicitly performed in autocommit mode, regardless of the autocommit setting.RENAME TO操作在autocommit模式下隐式执行,与autocommit设置无关。

A RENAME TO operation cannot be performed while LOCK TABLES or FLUSH TABLES WITH READ LOCK is in effect for tables that reside in the tablespace.当具有读锁的锁表或刷新表对驻留在表空间中的表生效时,无法执行重命名为操作。

Exclusive metadata locks are taken on tables that reside in a general tablespace while the tablespace is renamed, which prevents concurrent DDL. 在重命名常规表空间时,对驻留在该表空间中的表使用独占元数据锁,这会阻止并发DDL。Concurrent DML is supported.支持并发DML。

The CREATE TABLESPACE privilege is required to rename an InnoDB general tablespace.重命名InnoDB通用表空间需要CREATE TABLESPACE权限。

The AUTOEXTEND_SIZE option defines the amount by which InnoDB extends the size of a tablespace when it becomes full. AUTOEXTEND_SIZE选项定义InnoDB在表空间满时扩展表空间大小的量。Introduced in MySQL 8.0.23. 在MySQL 8.0.23中引入。The setting must be a multiple of 4MB. 该设置必须是4MB的倍数。The default setting is 0, which causes the tablespace to be extended according to the implicit default behavior. 默认设置为0,这将根据隐式默认行为扩展表空间。For more information, see Section 15.6.3.9, “Tablespace AUTOEXTEND_SIZE Configuration”.有关更多信息,请参阅第15.6.3.9节,“表空间自动扩展大小配置”

The ENCRYPTION clause enables or disables page-level data encryption for an InnoDB general tablespace or the mysql system tablespace. ENCRYPTION子句启用或禁用InnoDB通用表空间或mysql系统表空间的页面级数据加密。Encryption support for general tablespaces was introduced in MySQL 8.0.13. MySQL 8.0.13中引入了对通用表空间的加密支持。Encryption support for the mysql system tablespace was introduced in MySQL 8.0.16.mysql 8.0.16中引入了对mysql系统表空间的加密支持。

A keyring plugin must be installed and configured before encryption can be enabled.在启用加密之前,必须安装并配置密钥环插件。

As of MySQL 8.0.16, if the table_encryption_privilege_check variable is enabled, the TABLE_ENCRYPTION_ADMIN privilege is required to alter a general tablespace with an ENCRYPTION clause setting that differs from the default_table_encryption setting.从MySQL 8.0.16开始,如果启用了table_encryption_privilege_check变量,则需要TABLE_ENCRYPTION_ADMIN权限来更改具有不同于default_table_encryption设置的ENCRYPTION子句设置的常规表空间。

Enabling encryption for a general tablespace fails if any table in the tablespace belongs to a schema defined with DEFAULT ENCRYPTION='N'. 如果表空间中的任何表属于使用DEFAULT ENCRYPTION='N'定义的架构,则为常规表空间启用加密将失败。Similarly, disabling encryption fails if any table in the general tablespace belongs to a schema defined with DEFAULT ENCRYPTION='Y'. 类似地,如果常规表空间中的任何表属于使用默认DEFAULT ENCRYPTION='Y'定义的模式,则禁用加密将失败。The DEFAULT ENCRYPTION schema option was introduced in MySQL 8.0.16.MySQL 8.0.16中引入了DEFAULT ENCRYPTION架构选项。

If an ALTER TABLESPACE statement executed on a general tablespace does not include an ENCRYPTION clause, the tablespace retains its current encryption status, regardless of the default_table_encryption setting.如果在常规表空间上执行的ALTER TABLESPACE语句不包含ENCRYPTION子句,则无论default_table_encryption设置如何,该表空间都将保留其当前加密状态。

When a general tablespace or the mysql system tablespace is encrypted, all tables residing in the tablespace are encrypted. 加密常规表空间或mysql系统表空间时,表空间中的所有表都会加密。Likewise, a table created in an encrypted tablespace is encrypted.同样,在加密表空间中创建的表也是加密的。

The INPLACE algorithm is used when altering the ENCRYPTION attribute of a general tablespace or the mysql system tablespace. 当更改常规表空间或mysql系统表空间的ENCRYPTION属性时,将使用INPLACE算法。The INPLACE algorithm permits concurrent DML on tables that reside in the tablespace. INPLACE算法允许对驻留在表空间中的表执行并发DML。Concurrent DDL is blocked.并发DDL被阻止。

For more information, see Section 15.13, “InnoDB Data-at-Rest Encryption”.有关更多信息,请参阅第15.13节,“InnoDB静态数据加密”

The ENGINE_ATTRIBUTE option (available as of MySQL 8.0.21) is used to specify tablespace attributes for primary storage engines. ENGINE_ATTRIBUTE选项(从MySQL 8.0.21开始提供)用于为主存储引擎指定表空间属性。The option is reserved for future use.该选项保留供将来使用。

Permitted values are a string literal containing a valid JSON document or an empty string (''). 允许的值是包含有效JSON文档的字符串文字或空字符串('')。Invalid JSON is rejected.无效的JSON会被拒绝。

ALTER TABLESPACE ts1 ENGINE_ATTRIBUTE='{"key":"value"}';

ENGINE_ATTRIBUTE values can be repeated without error. ENGINE_ATTRIBUTE值可以无错误地重复。In this case, the last specified value is used.在这种情况下,将使用最后指定的值。

ENGINE_ATTRIBUTE values are not checked by the server, nor are they cleared when the table's storage engine is changed.服务器不会检查ENGINE_ATTRIBUTE,也不会在更改表的存储引擎时清除这些值。

It is not permitted to alter an individual element of a JSON attribute value. 不允许更改JSON属性值的单个元素。You can only add or replace an attribute.只能添加或替换属性。