MySQL :: MySQL 8.0 Reference Manual :: 17.6.3.2 File-Per-Table Tablespaces (original) (raw)

17.6.3.2 File-Per-Table Tablespaces

A file-per-table tablespace contains data and indexes for a singleInnoDB table, and is stored on the file system in a single data file.

File-per-table tablespace characteristics are described under the following topics in this section:

File-Per-Table Tablespace Configuration

InnoDB creates tables in file-per-table tablespaces by default. This behavior is controlled by theinnodb_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 aSET GLOBAL statement. Changing the setting at runtime requires privileges sufficient to set global system variables. See Section 7.1.9.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;
File-Per-Table Tablespace Data Files

A file-per-table tablespace is created in an.ibd data file in a schema directory under the MySQL data directory. The .ibd file is named for the table (_`tablename`_.ibd). For example, the data file for table test.t1 is created in the test directory under the MySQL data directory:

mysql> USE test;

mysql> CREATE TABLE t1 (
   id INT PRIMARY KEY AUTO_INCREMENT,
   name VARCHAR(100)
 ) ENGINE = InnoDB;

$> cd /path/to/mysql/data/test
$> ls
t1.ibd

You can use the DATA DIRECTORY clause of theCREATE TABLE statement to implicitly create a file-per-table tablespace data file outside of the data directory. For more information, seeSection 17.6.1.2, “Creating Tables Externally”.

File-Per-Table Tablespace Advantages

File-per-table tablespaces have the following advantages over shared tablespaces such as the system tablespace or general tablespaces.

File-Per-Table Tablespace Disadvantages

File-per-table tablespaces have the following disadvantages compared to shared tablespaces such as the system tablespace or general tablespaces.