CREATE [UNDO] TABLESPACEtablespace_name
InnoDB and NDB: [ADD DATAFILE 'file_name
'] [AUTOEXTEND_SIZE [=]value
] InnoDB only: [FILE_BLOCK_SIZE = value] [ENCRYPTION [=] {'Y' | 'N'}] NDB only: USE LOGFILE GROUPlogfile_group
[EXTENT_SIZE [=]extent_size
] [INITIAL_SIZE [=]initial_size
] [MAX_SIZE [=]max_size
] [NODEGROUP [=]nodegroup_id
] [WAIT] [COMMENT [=] 'string
'] InnoDB and NDB: [ENGINE [=]engine_name
] Reserved for future use: [ENGINE_ATTRIBUTE [=] 'string
']
This statement is used to create a tablespace. 此语句用于创建表空间。The precise syntax and semantics depend on the storage engine used. 精确的语法和语义取决于所使用的存储引擎。In standard MySQL releases, this is always an 在标准MySQL版本中,这始终是一个InnoDB
tablespace. InnoDB
表空间。MySQL NDB Cluster also supports tablespaces using the MySQL NDB集群还支持使用NDB
storage engine.NDB
存储引擎的表空间。
InnoDB
的考虑因素CREATE TABLESPACE
syntax is used to create general tablespaces or undo tablespaces. CREATE TABLESPACE
语法用于创建常规表空间或撤消表空间。The 必须指定MySQL 8.0.14中引入的UNDO
keyword, introduced in MySQL 8.0.14, must be specified to create an undo tablespace.UNDO
关键字才能创建撤销表空间。
A general tablespace is a shared tablespace. 通用表空间是共享表空间。It can hold multiple tables, and supports all table row formats. 它可以容纳多个表,并支持所有表行格式。General tablespaces can be created in a location relative to or independent of the data directory.可以在相对于或独立于数据目录的位置创建常规表空间。
After creating an 创建InnoDB
general tablespace, use CREATE TABLE
or tbl_name
... TABLESPACE [=] tablespace_name
ALTER TABLE
to add tables to the tablespace. tbl_name
TABLESPACE [=] tablespace_name
InnoDB
通用表空间后,使用CREATE TABLE
或tbl_name
... TABLESPACE [=] tablespace_name
ALTER TABLE
来将表添加到表空间。tbl_name
TABLESPACE [=] tablespace_name
For more information, see Section 15.6.3.3, “General Tablespaces”.有关更多信息,请参阅第15.6.3.3节,“通用表空间”。
Undo tablespaces contain undo logs. Undo tablespaces can be created in a chosen location by specifying a fully qualified data file path. 撤消表空间包含撤消日志。通过指定完全限定的数据文件路径,可以在选定位置创建撤消表空间。For more information, see Section 15.6.3.4, “Undo Tablespaces”.有关更多信息,请参阅第15.6.3.4节,“撤消表空间”。
This statement is used to create a tablespace, which can contain one or more data files, providing storage space for NDB Cluster Disk Data tables (see Section 23.5.10, “NDB Cluster Disk Data Tables”). 此语句用于创建一个表空间,该表空间可以包含一个或多个数据文件,为NDB群集磁盘数据表提供存储空间(请参阅第23.5.10节,“NDB群集磁盘数据表”)。One data file is created and added to the tablespace using this statement. 使用此语句创建一个数据文件并将其添加到表空间。Additional data files may be added to the tablespace by using the 可以使用ALTER TABLESPACE
statement (see Section 13.1.10, “ALTER TABLESPACE Statement”).ALTER TABLESPACE
语句将其他数据文件添加到表空间(请参阅第13.1.10节,“ALTER TABLESPACE语句”)。
All NDB Cluster Disk Data objects share the same namespace. 所有NDB群集磁盘数据对象共享相同的命名空间。This means that each Disk Data object must be uniquely named (and not merely each Disk Data object of a given type). 这意味着每个磁盘数据对象必须具有唯一的名称(而不仅仅是给定类型的每个磁盘数据对象)。For example, you cannot have a tablespace and a log file group with the same name, or a tablespace and a data file with the same name.例如,不能有同名的表空间和日志文件组,也不能有同名的表空间和数据文件。
A log file group of one or more 必须将一个或多个UNDO
log files must be assigned to the tablespace to be created with the USE LOGFILE GROUP
clause. UNDO
日志文件的日志文件组分配给使用USE LOGFILE GROUP
子句创建的表空间。logfile_group
must be an existing log file group created with CREATE LOGFILE GROUP
(see Section 13.1.16, “CREATE LOGFILE GROUP Statement”). logfile_group
必须是使用CREATE LOGFILE GROUP
创建的现有日志文件组(请参阅第13.1.16节,“CREATE LOGFILE GROUP语句”)。Multiple tablespaces may use the same log file group for 多个表空间可以使用相同的日志文件组来撤消日志记录。UNDO
logging.
When setting 设置EXTENT_SIZE
or INITIAL_SIZE
, you may optionally follow the number with a one-letter abbreviation for an order of magnitude, similar to those used in my.cnf
. EXTENT_SIZE
或INITIAL_SIZE
时,您可以选择在数字后面加一个一个字母的缩写,表示数量级,类似于my.cnf
中使用的缩写。Generally, this is one of the letters 通常,这是字母M
(for megabytes) or G
(for gigabytes).M
(表示兆字节)或G
(表示千兆字节)中的一个。
INITIAL_SIZE
and EXTENT_SIZE
are subject to rounding as follows:INITIAL_SIZE
和EXTENT_SIZE
以四舍五入为准,如下所示:
EXTENT_SIZE
is rounded up to the nearest whole multiple of 32K.EXTENT_SIZE
向上舍入为32K的整数倍。
INITIAL_SIZE
is rounded down to the nearest whole multiple of 32K; this result is rounded up to the nearest whole multiple of EXTENT_SIZE
(after any rounding).INITIAL_SIZE
向下舍入为32K的整数倍;此结果将向上舍入为EXTENT_SIZE
的最接近整数倍(在任何舍入之后)。
NDB
reserves 4% of a tablespace for data node restart operations. NDB
为数据节点重启操作保留了4%的表空间。This reserved space cannot be used for data storage.此保留空间不能用于数据存储。
The rounding just described is done explicitly, and a warning is issued by the MySQL Server when any such rounding is performed. 刚才描述的舍入是显式完成的,当执行任何此类舍入时,MySQL服务器会发出警告。The rounded values are also used by the NDB kernel for calculating NDB内核还使用舍入值来计算INFORMATION_SCHEMA.FILES
column values and other purposes. INFORMATION_SCHEMA.FILES
列值和其他用途。However, to avoid an unexpected result, we suggest that you always use whole multiples of 32K in specifying these options.但是,为了避免意外结果,我们建议您在指定这些选项时始终使用32K的整数倍。
When 当CREATE TABLESPACE
is used with ENGINE [=] NDB
, a tablespace and associated data file are created on each Cluster data node. CREATE TABLESPACE
与ENGINE [=] NDB
一起使用时,会在每个集群数据节点上创建一个表空间和关联的数据文件。You can verify that the data files were created and obtain information about them by querying the 您可以通过查询INFORMATION_SCHEMA.FILES
table. INFORMATION_SCHEMA.FILES
表来验证数据文件是否已创建,并获取有关这些文件的信息。(See the example later in this section.)(请参见本节后面的示例。)
(See Section 26.3.15, “The INFORMATION_SCHEMA FILES Table”.)(请参阅第26.3.15节,“信息模式文件表”。)
ADD DATAFILE
: Defines the name of a tablespace data file. :定义表空间数据文件的名称。This option is always required when creating an 创建NDB
tablespace; for InnoDB
in MySQL 8.0.14 and later, it is required only when creating an undo tablespace. NDB
表空间时始终需要此选项;对于MySQL 8.0.14及更高版本中的InnoDB
,只有在创建撤消表空间时才需要它。The
, including any specified path, must be quoted with single or double quotation marks. file_name
file_name
(包括任何指定路径)必须用单引号或双引号引起来。File names (not counting the file extension) and directory names must be at least one byte in length. 文件名(不包括文件扩展名)和目录名的长度必须至少为一个字节。Zero length file names and directory names are not supported.不支持零长度文件名和目录名。
Because there are considerable differences in how 由于InnoDB
and NDB
treat data files, the two storage engines are covered separately in the discussion that follows.InnoDB
和NDB
处理数据文件的方式存在很大差异,因此下面的讨论将分别讨论这两个存储引擎。
InnoDB data files.InnoDB
数据文件。 An InnoDB
tablespace supports only a single data file, whose name must include a .ibd
extension.InnoDB
表空间只支持单个数据文件,其名称必须包含.ibd
扩展名。
To place an 要将InnoDB
general tablespace data file in a location outside of the data directory, include a fully qualified path or a path relative to the data directory. InnoDB
通用表空间数据文件放置在数据目录之外的位置,请包括完全限定路径或相对于数据目录的路径。Only a fully qualified path is permitted for undo tablespaces. 撤消表空间只允许使用完全限定路径。If you do not specify a path, a general tablespace is created in the data directory. 如果不指定路径,将在数据目录中创建常规表空间。An undo tablespace created without specifying a path is created in the directory defined by the 在innodb_undo_directory
variable. innodb_undo_directory
变量定义的目录中创建一个未指定路径的撤销表空间。If the 如果innodb_undo_directory
variable is undefined, undo tablespaces are created in the data directory.innodb_undo_directory
变量未定义,则在数据目录中创建撤销表空间。
To avoid conflicts with implicitly created file-per-table tablespaces, creating an 为避免与隐式创建的每表文件表空间冲突,不支持在数据目录下的子目录中创建InnoDB
general tablespace in a subdirectory under the data directory is not supported. InnoDB
通用表空间。When creating a general tablespace or undo tablespace outside of the data directory, the directory must exist and must be known to 在数据目录之外创建常规表空间或撤消表空间时,目录必须存在,并且在创建表空间之前InnoDB
prior to creating the tablespace. InnoDB
必须知道该目录。To make a directory known to 要使InnoDB
, add it to the innodb_directories
value or to one of the variables whose values are appended to the innodb_directories
value. InnoDB
知道目录,请将其添加到innodb_directories
值或其值附加到innodb_directories
的变量之一。innodb_directories
is a read-only variable. innodb_directories
是一个只读变量。Configuring it requires restarting the server.配置它需要重新启动服务器。
If the 如果在创建ADD DATAFILE
clause is not specified when creating an InnoDB
tablespace, a tablespace data file with a unique file name is created implicitly. InnoDB
表空间时未指定ADD DATAFILE
子句,则隐式创建具有唯一文件名的表空间数据文件。The unique file name is a 128 bit UUID formatted into five groups of hexadecimal numbers separated by dashes (唯一文件名是一个128位UUID,格式为五组十六进制数,用破折号分隔(aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
). aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
)。A file extension is added if required by the storage engine. 如果存储引擎需要,将添加文件扩展名。An .ibd
file extension is added for InnoDB
general tablespace data files. InnoDB
通用表空间数据文件增加了.ibd
文件扩展名。In a replication environment, the data file name created on the replication source server is not the same as the data file name created on the replica.在复制环境中,在复制源服务器上创建的数据文件名与在复制副本上创建的数据文件名不同。
As of MySQL 8.0.17, the 从MySQL 8.0.17开始,在创建ADD DATAFILE
clause does not permit circular directory references when creating an InnoDB
tablespace. InnoDB
表空间时,ADD DATAFILE
子句不允许循环目录引用。For example, the circular directory reference (例如,不允许以下语句中的循环目录引用(/../
) in the following statement is not permitted:/../
):
CREATE TABLESPACE ts1 ADD DATAFILE ts1.ibd 'any_directory
/../ts1.ibd';
An exception to this restriction exists on Linux, where a circular directory reference is permitted if the preceding directory is a symbolic link. Linux上存在此限制的例外情况,如果前面的目录是符号链接,则允许循环目录引用。For example, the data file path in the example above is permitted if 例如,如果any_directory
is a symbolic link. any_directory
是符号链接,则允许上面示例中的数据文件路径。(It is still permitted for data file paths to begin with '(仍然允许数据文件路径以“../
'.)../
”开头。)
NDB data files.NDB数据文件。 An 一个NDB表空间支持多个数据文件,可以有任何合法的文件名;在NDB集群表空间创建之后,可以使用NDB
tablespace supports multiple data files which can have any legal file names; more data files can be added to an NDB Cluster tablespace following its creation by using an ALTER TABLESPACE
statement.ALTER TABLE SPACE
语句将更多数据文件添加到NDB集群表空间。
An 默认情况下,在数据节点文件系统目录中创建NDB
tablespace data file is created by default in the data node file system directory—that is, the directory named ndb_
under the data node's data directory (nodeid
_fs/TSDataDir
), where nodeid
is the data node's NodeId
. NDB
表空间数据文件,即数据节点的数据目录(DataDir
)下名为ndb_
的目录,其中nodeid
_fs/TSnodeid
是数据节点的NodeId
。To place the data file in a location other than the default, include an absolute directory path or a path relative to the default location. 要将数据文件放置在默认位置以外的位置,请包括绝对目录路径或相对于默认位置的路径。If the directory specified does not exist, 如果指定的目录不存在,NDB
attempts to create it; the system user account under which the data node process is running must have the appropriate permissions to do so.NDB
将尝试创建该目录;运行数据节点进程的系统用户帐户必须具有相应的权限。
When determining the path used for a data file, 在确定数据文件使用的路径时,NDB
does not expand the ~
(tilde) character.NDB
不会展开~
(波浪)字符。
When multiple data nodes are run on the same physical host, the following considerations apply:当多个数据节点在同一物理主机上运行时,应考虑以下事项:
You cannot specify an absolute path when creating a data file.创建数据文件时不能指定绝对路径。
It is not possible to create tablespace data files outside the data node file system directory, unless each data node has a separate data directory.不可能在数据节点文件系统目录之外创建表空间数据文件,除非每个数据节点都有单独的数据目录。
If each data node has its own data directory, data files can be created anywhere within this directory.如果每个数据节点都有自己的数据目录,则可以在此目录中的任何位置创建数据文件。
If each data node has its own data directory, it may also be possible to create a data file outside the node's data directory using a relative path, as long as this path resolves to a unique location on the host file system for each data node running on that host.如果每个数据节点都有自己的数据目录,也可以使用相对路径在节点的数据目录外创建数据文件,只要该路径解析为主机上运行的每个数据节点在主机文件系统上的唯一位置。
FILE_BLOCK_SIZE
: This option—which is specific to :此选项特定于InnoDB
general tablespaces, and is ignored by NDB
—defines the block size for the tablespace data file. InnoDB
通用表空间,NDB
会忽略它,它定义表空间数据文件的块大小。Values can be specified in bytes or kilobytes. 可以以字节或千字节为单位指定值。For example, an 8 kilobyte file block size can be specified as 8192 or 8K. 例如,8KB的文件块大小可以指定为8192或8K。If you do not specify this option, 如果未指定此选项,则FILE_BLOCK_SIZE
defaults to the innodb_page_size
value. FILE_BLOCK_SIZE
默认为innodb_page_size
值。如果要使用表空间存储压缩的FILE_BLOCK_SIZE
is required when you intend to use the tablespace for storing compressed InnoDB
tables (ROW_FORMAT=COMPRESSED
). InnoDB
表(ROW_FORMAT=COMPRESSED
),则需要FILE_BLOCK_SIZE
。In this case, you must define the tablespace 在这种情况下,创建表空间时必须定义表空间FILE_BLOCK_SIZE
when creating the tablespace.FILE_BLOCK_SIZE
。
If 如果FILE_BLOCK_SIZE
is equal the innodb_page_size
value, the tablespace can contain only tables having an uncompressed row format (COMPACT
, REDUNDANT
, and DYNAMIC
). FILE_BLOCK_SIZE
等于innodb_page_size
值,则表空间只能包含具有未压缩行格式(COMPACT
、REDUNDANT
和DYNAMIC
)的表。Tables with a 具有COMPRESSED
row format have a different physical page size than uncompressed tables. COMPRESSED
行格式的表与未压缩的表具有不同的物理页大小。Therefore, compressed tables cannot coexist in the same tablespace as uncompressed tables.因此,压缩表不能与未压缩表共存于同一表空间中。
For a general tablespace to contain compressed tables, 对于包含压缩表的常规表空间,必须指定FILE_BLOCK_SIZE
must be specified, and the FILE_BLOCK_SIZE
value must be a valid compressed page size in relation to the innodb_page_size
value. FILE_BLOCK_SIZE
,并且FILE_BLOCK_SIZE
值必须是相对于innodb_page_size
值的有效压缩页面大小。Also, the physical page size of the compressed table (此外,压缩表的物理页大小(KEY_BLOCK_SIZE
) must be equal to FILE_BLOCK_SIZE/1024
. KEY_BLOCK_SIZE
)必须等于FILE_BLOCK_SIZE/1024
。For example, if 例如,如果innodb_page_size=16K
, and FILE_BLOCK_SIZE=8K
, the KEY_BLOCK_SIZE
of the table must be 8. innodb_page_size=16K
,而FILE_BLOCK_size=8K
,则表的KEY_BLOCK_SIZE
必须为8。For more information, see Section 15.6.3.3, “General Tablespaces”.有关更多信息,请参阅第15.6.3.3节,“常规表空间”。
USE LOGFILE GROUP
: Required for :对于NDB
, this is the name of a log file group previously created using CREATE LOGFILE GROUP
. NDB
是必需的,这是以前使用CREATE LOGFILE GROUP
创建的日志文件组的名称。Not supported for InnoDB
, where it fails with an error.InnoDB
不支持,因错误而失败。
EXTENT_SIZE
: This option is specific to NDB, and is not supported by InnoDB, where it fails with an error. :此选项特定于NDB,InnoDB
不支持此选项,因为它会因错误而失败。EXTENT_SIZE
sets the size, in bytes, of the extents used by any files belonging to the tablespace. EXTENT_SIZE
(区段大小)设置属于表空间的任何文件所使用的区段的大小(以字节为单位)。The default value is 1M. 默认值为1M。The minimum size is 32K, and theoretical maximum is 2G, although the practical maximum size depends on a number of factors. 最小尺寸为32K,理论最大尺寸为2G,但实际最大尺寸取决于许多因素。In most cases, changing the extent size does not have any measurable effect on performance, and the default value is recommended for all but the most unusual situations.在大多数情况下,更改数据块大小不会对性能产生任何可测量的影响,除了最不寻常的情况外,建议使用默认值。
An extent is a unit of disk space allocation. 区段是磁盘空间分配的一个单位。One extent is filled with as much data as that extent can contain before another extent is used. 在使用另一个扩展数据块之前,一个扩展数据块将填充该扩展数据块所能包含的数据量。In theory, up to 65,535 (64K) extents may used per data file; however, the recommended maximum is 32,768 (32K). 理论上,每个数据文件最多可使用65535(64K)个扩展数据块;但是,建议的最大值为32768(32K)。The recommended maximum size for a single data file is 32G—that is, 32K extents × 1 MB per extent. 单个数据文件的建议最大大小为32G,即32K数据块,每个数据块1 MB。In addition, once an extent is allocated to a given partition, it cannot be used to store data from a different partition; an extent cannot store data from more than one partition. 此外,一旦一个区段被分配给一个给定的分区,它就不能用于存储来自不同分区的数据;数据块不能存储来自多个分区的数据。This means, for example that a tablespace having a single datafile whose 这意味着,例如,具有单个数据文件的表空间,其INITIAL_SIZE
(described in the following item) is 256 MB and whose EXTENT_SIZE
is 128M has just two extents, and so can be used to store data from at most two different disk data table partitions.INITIAL_SIZE
(在下一项中描述)为256 MB,而其EXTENT_SIZE
为128M,该表空间只有两个区段,因此可用于存储最多两个不同磁盘数据表分区的数据。
You can see how many extents remain free in a given data file by querying the 通过查询INFORMATION_SCHEMA.FILES
table, and so derive an estimate for how much space remains free in the file. INFORMATION_SCHEMA.FILES
表,您可以看到给定数据文件中有多少数据块保持可用,从而得出文件中有多少空间保持可用的估计值。For further discussion and examples, see Section 26.3.15, “The INFORMATION_SCHEMA FILES Table”.有关进一步的讨论和示例,请参阅第26.3.15节,“INFORMATION_SCHEMA文件表”。
INITIAL_SIZE
: This option is specific to :此选项特定于NDB
, and is not supported by InnoDB
, where it fails with an error.NDB
,InnoDB
不支持此选项,因为它会因错误而失败。
The INITIAL_SIZE
parameter sets the total size in bytes of the data file that was specific using ADD DATATFILE
. INITIAL_SIZE
参数设置数据文件的总大小(以字节为单位),该文件是使用ADD DATATFILE
指定的。Once this file has been created, its size cannot be changed; however, you can add more data files to the tablespace using 创建此文件后,无法更改其大小;但是,您可以使用ALTER TABLESPACE ... ADD DATAFILE
.ALTER TABLESPACE ... ADD DATAFILE
向表空间添加更多数据文件。
INITIAL_SIZE
is optional; its default value is 134217728 (128 MB).INITIAL_SIZE
是可选的;其默认值为134217728(128MB)。
On 32-bit systems, the maximum supported value for 在32位系统上,INITIAL_SIZE
is 4294967296 (4 GB).INITIAL_SIZE
的最大支持值为4294967296(4 GB)。
AUTOEXTEND_SIZE
: Ignored by MySQL prior to MySQL 8.0.23; From MySQL 8.0.23, defines the amount by which :在MySQL 8.0.23之前被MySQL忽略;MySQL 8.0.23定义了InnoDB
extends the size of the tablespace when it becomes full. InnoDB
在表空间满时扩展表空间大小的量。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节,“表空间自动扩展大小配置”。
Has no effect in any release of MySQL NDB Cluster 8.0, regardless of the storage engine used.无论使用何种存储引擎,在MySQL NDB Cluster 8.0的任何版本中都不起作用。
MAX_SIZE
: Currently ignored by MySQL; reserved for possible future use. :目前被MySQL忽略;保留以备将来可能使用。Has no effect in any release of MySQL 8.0 or MySQL NDB Cluster 8.0, regardless of the storage engine used.无论使用何种存储引擎,在MySQL 8.0或MySQL NDB Cluster 8.0的任何版本中都不起作用。
NODEGROUP
: Currently ignored by MySQL; reserved for possible future use. :目前被MySQL忽略;保留以备将来可能使用。Has no effect in any release of MySQL 8.0 or MySQL NDB Cluster 8.0, regardless of the storage engine used.无论使用何种存储引擎,在MySQL 8.0或MySQL NDB Cluster 8.0的任何版本中都不起作用。
WAIT
: Currently ignored by MySQL; reserved for possible future use. :目前被MySQL忽略;保留以备将来可能使用。Has no effect in any release of MySQL 8.0 or MySQL NDB Cluster 8.0, regardless of the storage engine used.无论使用何种存储引擎,在MySQL 8.0或MySQL NDB Cluster 8.0的任何版本中都不起作用。
COMMENT
: Currently ignored by MySQL; reserved for possible future use. :目前被MySQL忽略;保留以备将来可能使用。Has no effect in any release of MySQL 8.0 or MySQL NDB Cluster 8.0, regardless of the storage engine used.无论使用何种存储引擎,在MySQL 8.0或MySQL NDB Cluster 8.0的任何版本中都不起作用。
The ENCRYPTION
clause enables or disables page-level data encryption for an InnoDB
general tablespace. ENCRYPTION
子句启用或禁用InnoDB
通用表空间的页面级数据加密。Encryption support for general tablespaces was introduced in MySQL 8.0.13.MySQL 8.0.13中引入了对通用表空间的加密支持。
As of MySQL 8.0.16, if the 从MySQL 8.0.16开始,如果未指定ENCRYPTION
clause is not specified, the default_table_encryption
setting controls whether encryption is enabled. ENCRYPTION
子句,则default_table_encryption
设置控制是否启用加密。The ENCRYPTION
clause overrides the default_table_encryption
setting. ENCRYPTION
子句覆盖default_table_encryption
设置。However, if the 但是,如果启用了table_encryption_privilege_check
variable is enabled, the TABLE_ENCRYPTION_ADMIN
privilege is required to use an ENCRYPTION
clause setting that differs from the default_table_encryption
setting.table_encryption_privilege_check
变量,则需要TABLE_ENCRYPTION_ADMIN
权限才能使用与default_table_encryption
设置不同的ENCRYPTION
子句设置。
A keyring plugin must be installed and configured before an encryption-enabled tablespace can be created.在创建启用加密的表空间之前,必须安装并配置keyring插件。
When a general tablespace is encrypted, all tables residing in the tablespace are encrypted. 加密常规表空间时,表空间中的所有表都会加密。Likewise, a table created in an encrypted tablespace is encrypted.同样,在加密表空间中创建的表也是加密的。
For more information, see Section 15.13, “InnoDB Data-at-Rest Encryption”有关更多信息,请参阅第15.13节,“InnoDB
静态数据加密”。
ENGINE
: Defines the storage engine which uses the tablespace, where :定义使用表空间的存储引擎,其中engine_name
is the name of the storage engine. engine_name
是存储引擎的名称。Currently, only the 目前,标准MySQL 8.0版本只支持InnoDB
storage engine is supported by standard MySQL 8.0 releases. InnoDB
存储引擎。MySQL NDB Cluster supports both MySQL NDB集群同时支持NDB
and InnoDB
tablespaces. NDB
和InnoDB
表空间。The value of the 如果未指定该选项,则系统变量default_storage_engine
system variable is used for ENGINE
if the option is not specified.default_storage_engine
的值将用于ENGINE
。
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
被拒绝。
CREATE TABLESPACE ts1 ENGINE_ATTRIBUTE='{"key
":"value
"}';
ENGINE_ATTRIBUTE
values can be repeated without error. 值可以无误地重复。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.服务器不会检查值,更改表的存储引擎时也不会清除这些值。
For the rules covering the naming of MySQL tablespaces, see Section 9.2, “Schema Object Names”. 有关MySQL表空间命名的规则,请参阅第9.2节,“架构对象名称”。In addition to these rules, the slash character (“/”) is not permitted, nor can you use names beginning with 除这些规则外,斜杠字符(“/”)是不允许的,您也不能使用以innodb_
, as this prefix is reserved for system use.innodb_
开头的名称,因为此前缀保留供系统使用。
Creation of temporary general tablespaces is not supported.不支持创建临时常规表空间。
General tablespaces do not support temporary tables.常规表空间不支持临时表。
The TABLESPACE
option may be used with CREATE TABLE
or ALTER TABLE
to assign an InnoDB
table partition or subpartition to a file-per-table tablespace. TABLESPACE
选项可与CREATE TABLE
或ALTER TABLE
一起使用,为每个表空间的文件分配InnoDB
表分区或子分区。All partitions must belong to the same storage engine. 所有分区必须属于同一个存储引擎。Assigning table partitions to shared 不支持将表分区分配给共享InnoDB
tablespaces is not supported. InnoDB
表空间。Shared tablespaces include the 共享表空间包括InnoDB
system tablespace and general tablespaces.InnoDB
系统表空间和通用表空间。
General tablespaces support the addition of tables of any row format using 通用表空间支持使用CREATE TABLE ... TABLESPACE
. CREATE TABLE ... TABLESPACE
添加任何行格式的表。无需启用innodb_file_per_table
does not need to be enabled.innodb_file_per_table
。
innodb_strict_mode
is not applicable to general tablespaces. innodb_strict_mode
不适用于常规表空间。Tablespace management rules are strictly enforced independently of 表空间管理规则独立于innodb_strict_mode
. innodb_strict_mode
严格执行。If 如果CREATE TABLESPACE
parameters are incorrect or incompatible, the operation fails regardless of the innodb_strict_mode
setting. CREATE TABLESPACE
参数不正确或不兼容,则无论innodb_strict_mode
设置如何,操作都会失败。When a table is added to a general tablespace using 使用CREATE TABLE ... TABLESPACE
or ALTER TABLE ... TABLESPACE
, innodb_strict_mode
is ignored but the statement is evaluated as if innodb_strict_mode
is enabled.CREATE TABLE ... TABLESPACE
或ALTER TABLE ... TABLESPACE
将表添加到常规表空间时,innodb_strict_mode
被忽略,但该语句的计算方式与启用innodb_strict_mode
相同。
Use 使用DROP TABLESPACE
to remove a tablespace. DROP TABLESPACE
删除表空间。All tables must be dropped from a tablespace using 在删除表空间之前,必须使用DROP TABLE
prior to dropping the tablespace. DROP TABLE
从表空间中删除所有表。Before dropping an NDB Cluster tablespace you must also remove all its data files using one or more 在删除NDB群集表空间之前,还必须使用一个或多个ALTER TABLESPACE ... DROP DATATFILE
statements. ALTER TABLESPACE ... DROP DATATFILE
语句删除其所有数据文件。See Section 23.5.10.1, “NDB Cluster Disk Data Objects”.请参阅第23.5.10.1节,“NDB群集磁盘数据对象”。
All parts of an 添加到InnoDB
table added to an InnoDB
general tablespace reside in the general tablespace, including indexes and BLOB
pages.InnoDB
通用表空间的InnoDB
表的所有部分都位于通用表空间中,包括索引和BLOB
页面。
For an 对于分配给表空间的NDB
table assigned to a tablespace, only those columns which are not indexed are stored on disk, and actually use the tablespace data files. NDB
表,只有那些未编制索引的列存储在磁盘上,并且实际使用表空间数据文件。Indexes and indexed columns for all 所有NDB
tables are always kept in memory.NDB
表的索引和索引列始终保存在内存中。
Similar to the system tablespace, truncating or dropping tables stored in a general tablespace creates free space internally in the general tablespace .ibd data file which can only be used for new 与系统表空间类似,截断或删除存储在常规表空间中的表会在通用表空间.ibd数据文件内部创建可用空间,该文件只能用于新的InnoDB
data. InnoDB
数据。Space is not released back to the operating system as it is for file-per-table tablespaces.空间不会像每个表的文件表空间那样释放回操作系统。
A general tablespace is not associated with any database or schema.常规表空间不与任何数据库或模式相关联。
从属于常规表空间的表不支持ALTER TABLE ... DISCARD TABLESPACE
and ALTER TABLE ...IMPORT TABLESPACE
are not supported for tables that belong to a general tablespace.ALTER TABLE ... DISCARD TABLESPACE
和ALTER TABLE ...IMPORT TABLESPACE
。
The server uses tablespace-level metadata locking for DDL that references general tablespaces. 服务器对引用常规表空间的DDL使用表空间级元数据锁定。By comparison, the server uses table-level metadata locking for DDL that references file-per-table tablespaces.相比之下,服务器对每个表空间引用文件的DDL使用表级元数据锁定。
A generated or existing tablespace cannot be changed to a general tablespace.无法将生成的或现有的表空间更改为常规表空间。
There is no conflict between general tablespace names and file-per-table tablespace names. 常规表空间名称和每个表的文件表空间名称之间没有冲突。The “/” character, which is present in file-per-table tablespace names, is not permitted in general tablespace names.一般表空间名称中不允许使用文件/表空间名称中的“/”字符。
mysqldump and mysqlpump do not dump mysqldump和mysqlpump不转储InnoDB
CREATE TABLESPACE
statements.InnoDB
CREATE TABLESPACE
语句。
InnoDB
示例This example demonstrates creating a general tablespace and adding three uncompressed tables of different row formats.此示例演示如何创建常规表空间并添加三个不同行格式的未压缩表。
mysql>CREATE TABLESPACE `ts1` ADD DATAFILE 'ts1.ibd' ENGINE=INNODB;
mysql>CREATE TABLE t1 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=REDUNDANT;
mysql>CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=COMPACT;
mysql>CREATE TABLE t3 (c1 INT PRIMARY KEY) TABLESPACE ts1 ROW_FORMAT=DYNAMIC;
This example demonstrates creating a general tablespace and adding a compressed table. 此示例演示如何创建常规表空间和添加压缩表。The example assumes a default 该示例假定默认的innodb_page_size
value of 16K. innodb_page_size
值为16K。The FILE_BLOCK_SIZE
of 8192 requires that the compressed table have a KEY_BLOCK_SIZE
of 8.FILE_BLOCK_SIZE
8192要求压缩表的KEY_BLOCK_SIZE
为8。
mysql>CREATE TABLESPACE `ts2` ADD DATAFILE 'ts2.ibd' FILE_BLOCK_SIZE = 8192 Engine=InnoDB;
mysql>CREATE TABLE t4 (c1 INT PRIMARY KEY) TABLESPACE ts2 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;
This example demonstrates creating a general tablespace without specifying the 此示例演示如何在不指定ADD DATAFILE
clause, which is optional as of MySQL 8.0.14.ADD DATAFILE
子句的情况下创建常规表空间,该子句在MySQL 8.0.14中是可选的。
mysql> CREATE TABLESPACE `ts3` ENGINE=INNODB;
This example demonstrates creating an undo tablespace.此示例演示如何创建撤消表空间。
mysql> CREATE UNDO TABLESPACE undo_003
ADD DATAFILE 'undo_003
.ibu';
Suppose that you wish to create an NDB Cluster Disk Data tablespace named 假设您希望使用名为myts
using a datafile named mydata-1.dat
. mydata-1.dat
的数据文件创建名为myts
的NDB群集磁盘数据表空间。An NDB
tablespace always requires the use of a log file group consisting of one or more undo log files. NDB
表空间始终需要使用由一个或多个撤消日志文件组成的日志文件组。For this example, we first create a log file group named 对于本例,我们首先创建一个名为mylg
that contains one undo long file named myundo-1.dat
, using the CREATE LOGFILE GROUP
statement shown here:mylg
的日志文件组,其中包含一个名为myundo-1.dat
的撤销长文件,使用如下所示的CREATE LOGFILE GROUP
语句:
mysql>CREATE LOGFILE GROUP myg1
->ADD UNDOFILE 'myundo-1.dat'
->ENGINE=NDB;
Query OK, 0 rows affected (3.29 sec)
Now you can create the tablespace previously described using the following statement:现在可以使用以下语句创建前面描述的表空间:
mysql>CREATE TABLESPACE myts
->ADD DATAFILE 'mydata-1.dat'
->USE LOGFILE GROUP mylg
->ENGINE=NDB;
Query OK, 0 rows affected (2.98 sec)
You can now create a Disk Data table using a 现在,您可以使用CREATE TABLE
statement with the TABLESPACE
and STORAGE DISK
options, similar to what is shown here:CREATE TABLE
语句创建磁盘数据表,该语句带有TABLESPACE
和STORAGE DISK
选项,如下所示:
mysql>CREATE TABLE mytable (
->id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
->lname VARCHAR(50) NOT NULL,
->fname VARCHAR(50) NOT NULL,
->dob DATE NOT NULL,
->joined DATE NOT NULL,
->INDEX(last_name, first_name)
->)
->TABLESPACE myts STORAGE DISK
->ENGINE=NDB;
Query OK, 0 rows affected (1.41 sec)
It is important to note that only the 需要注意的是,由于dob
and joined
columns from mytable
are actually stored on disk, due to the fact that the id
, lname
, and fname
columns are all indexed.id
、lname
和fname
列都已编制索引,因此实际上只有mytable
中的dob
和joined
列存储在磁盘上。
As mentioned previously, when 如前所述,当CREATE TABLESPACE
is used with ENGINE [=] NDB
, a tablespace and associated data file are created on each NDB Cluster data node. CREATE TABLESPACE
与ENGINE [=] NDB
一起使用时,会在每个NDB集群数据节点上创建一个表空间和关联的数据文件。You can verify that the data files were created and obtain information about them by querying the 您可以通过查询INFORMATION_SCHEMA.FILES
table, as shown here:INFORMATION_SCHEMA.FILES
表来验证数据文件是否已创建,并获取有关这些文件的信息,如下所示:
mysql>SELECT FILE_NAME, FILE_TYPE, LOGFILE_GROUP_NAME, STATUS, EXTRA
->FROM INFORMATION_SCHEMA.FILES
->WHERE TABLESPACE_NAME = 'myts';
+--------------+------------+--------------------+--------+----------------+ | file_name | file_type | logfile_group_name | status | extra | +--------------+------------+--------------------+--------+----------------+ | mydata-1.dat | DATAFILE | mylg | NORMAL | CLUSTER_NODE=5 | | mydata-1.dat | DATAFILE | mylg | NORMAL | CLUSTER_NODE=6 | | NULL | TABLESPACE | mylg | NORMAL | NULL | +--------------+------------+--------------------+--------+----------------+ 3 rows in set (0.01 sec)
For additional information and examples, see Section 23.5.10.1, “NDB Cluster Disk Data Objects”.有关更多信息和示例,请参阅第23.5.10.1节,“NDB群集磁盘数据对象”。