Plan the location in advance, because you cannot use the
DATA DIRECTORY clause with the
ALTER TABLE statement. The
directory you specify could be on another storage device with
particular performance or capacity characteristics, such as a fast
SSD or a high-capacity
Within the destination directory, MySQL creates a subdirectory
corresponding to the database name, and within that a
.ibd file for the new table.
In the database directory beneath the MySQL
DATADIR directory, MySQL creates
file containing the path name for the table. The
.isl file is treated by MySQL
like a symbolic link. (Using actual
symbolic links has never been supported for
The following example demonstrates creating a file-per-table
tablespace outside the MySQL data directory. It shows the
.ibd created in the specified directory, and
.isl created in the database directory
beneath the MySQL data directory.
mysql> USE test; Database changed mysql> SHOW VARIABLES LIKE 'innodb_file_per_table'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_file_per_table | ON | +-----------------------+-------+ 1 row in set (0.00 sec) mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/alternative/directory'; Query OK, 0 rows affected (0.03 sec) # MySQL creates a .ibd file for the new table in a subdirectory that corresponding # to the database name db_user@ubuntu:~/alternative/directory/test$ ls t1.ibd # MySQL creates a .isl file containing the path name for the table in a directory # beneath the MySQL data directory db_user@ubuntu:~/mysql/data/test$ ls db.opt t1.frm t1.isl
As of MySQL 5.7.6, you can also use
CREATE TABLE ...
TABLESPACE in combination with the
DIRECTORY clause to create a file-per-table tablespace
outside the MySQL data directory. To do so, you must specify
innodb_file_per_table as the tablespace name.
CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE = innodb_file_per_table DATA DIRECTORY = '/alternative/directory';
You do not have to enable
innodb_file_per_table when using
MySQL initially holds the
.ibd file open,
preventing you from dismounting the device, but might
eventually close the table if the server is busy. Be careful
not to accidentally dismount an external device while MySQL is
running, or to start MySQL while the device is disconnected.
Attempting to access a table when the associated
.ibd file is missing causes a serious error
that requires a server restart.
A server restart might fail if the
file is still not at the expected path. In this case, manually
file in the database directory, and after restarting perform a
DROP TABLE to delete the
.frm file and remove the information about
the table from the data
Do not put MySQL tables on an NFS-mounted volume. NFS uses a message-passing protocol to write to files, which could cause data inconsistency if network messages are lost or received out of order.
If you use an LVM snapshot, file copy, or other file-based
mechanism to back up the
.ibd file, always
... FOR EXPORT statement first to make sure all
changes that were buffered in memory are
flushed to disk before the
DATA DIRECTORY clause is a supported
alternative to using symbolic
links, which has always been problematic and was never
supported for individual