Open lihongjie0209 opened 3 years ago
A file-per-table tablespace contains data and indexes for a single InnoDB table, and is stored on the file system in its own data file.
InnoDB
creates tables in file-per-table tablespaces by default. This behavior is controlled by the innodb_file_per_table
variable. Disabling innodb_file_per_table
causes InnoDB
to create tables in the system tablespace.
An innodb_file_per_table
setting can be specified in an option file or configured at runtime using a SET GLOBAL
statement. Changing the setting at runtime requires privileges sufficient to set global system variables. See Section 5.1.8.1, “System Variable Privileges”.
Option file:
[mysqld]
innodb_file_per_table=ON
Using SET GLOBAL
at runtime:
mysql> SET GLOBAL innodb_file_per_table=ON;
innodb_file_per_table
is enabled by default in MySQL 5.6 and higher. You might consider disabling it if backward compatibility with earlier versions of MySQL is a concern.
Undo tablespaces contain undo logs, which are collections of undo log records that contain information about how to undo the latest change by a transaction to a clustered index record. Undo logs exist within undo log segments, which are contained within rollback segments. The innodb_rollback_segments
variable defines the number of rollback segments allocated to each undo tablespace.
Undo logs can be stored in one or more undo tablespaces instead of the system tablespace. This layout differs from the default configuration in which undo logs reside in the system tablespace. The I/O patterns for undo logs make undo tablespaces good candidates for SSD storage, while keeping the system tablespace on hard disk storage.
The number of undo tablespaces used by InnoDB
is controlled by the innodb_undo_tablespaces
configuration option. This option can only be configured when initializing the MySQL instance. It cannot be changed afterward.
Note
The innodb_undo_tablespaces
configuration option is deprecated; expect it to be removed in a future release.
Undo tablespaces and individual segments inside those tablespaces cannot be dropped. However, undo logs stored in undo tablespaces can be truncated. For more information, see Truncating Undo Tablespaces.
system tablespace
The system tablespace is the storage area for the
InnoDB
data dictionary, the doublewrite buffer, the change buffer, and undo logs. It may also contain table and index data if tables are created in the system tablespace rather than file-per-table or general tablespaces.The system tablespace can have one or more data files. By default, a single system tablespace data file, named
ibdata1
, is created in the data directory. The size and number of system tablespace data files is defined by theinnodb_data_file_path
startup option. For configuration information, see System Tablespace Data File Configuration.Resizing the System Tablespace
This section describes how to increase or decrease the size of the system tablespace.
Increasing the Size of the System Tablespace
The easiest way to increase the size of the system tablespace is to configure it to be auto-extending. To do so, specify the
autoextend
attribute for the last data file in theinnodb_data_file_path
setting, and restart the server. For example:When the
autoextend
attribute is specified, the data file automatically increases in size by 8MB increments as space is required. Theinnodb_autoextend_increment
variable controls the increment size.You can also increase system tablespace size by adding another data file. To do so:
innodb_data_file_path
setting is defined with theautoextend
attribute, remove it, and modify the size attribute to reflect the current data file size. To determine the appropriate data file size to specify, check your file system for the file size, and round that value down to the closest MB value, where a MB is equal to 1024 x 1024.innodb_data_file_path
setting, optionally specifying theautoextend
attribute. Theautoextend
attribute can be specified only for the last data file in theinnodb_data_file_path
setting.For example, this tablespace has one auto-extending data file:
Suppose that the data file has grown to 988MB over time. This is the
innodb_data_file_path
setting after modifying the size attribute to reflect the current data file size, and after specifying a new 50MB auto-extending data file:When adding a new data file, do not specify an existing file name.
InnoDB
creates and initializes the new data file when you start the server.