PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
There are different reasons for creatingInnoDB tables externally; that is, creating tables outside of the data directory. Those reasons might include space management, I/O optimization, or placing tables on a storage device with particular performance or capacity characteristics, for example.
InnoDB supports the following methods for creating tables externally:
You can create anInnoDB table in an external directory by specifying aDATA DIRECTORY clause in theCREATE TABLE statement.
CREATE TABLE t1 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/external/directory'; TheDATA DIRECTORY clause is supported for tables created in file-per-table tablespaces. Tables are implicitly created in file-per-table tablespaces when theinnodb_file_per_table variable is enabled, which it is by default.
mysql> SELECT @@innodb_file_per_table;+-------------------------+| @@innodb_file_per_table |+-------------------------+| 1 |+-------------------------+For more information about file-per-table tablespaces, seeSection 17.6.3.2, “File-Per-Table Tablespaces”.
When you specify aDATA DIRECTORY clause in aCREATE TABLE statement, the table's data file () is created in a schema directory under the specified directory.table_name.ibd
Tables and table partitions created outside of the data directory using theDATA DIRECTORY clause are restricted to directories known toInnoDB. This requirement permits database administrators to control where tablespace data files are created and ensures that data files can be found during recovery (seeTablespace Discovery During Crash Recovery). Known directories are those defined by thedatadir,innodb_data_home_dir, andinnodb_directories variables. You can use the following statement to check those settings:
mysql> SELECT @@datadir,@@innodb_data_home_dir,@@innodb_directories; If the directory you want to use is unknown, add it to theinnodb_directories setting before you create the table. Theinnodb_directories variable is read-only. Configuring it requires restarting the server. For general information about setting system variables, seeSection 7.1.9, “Using System Variables”.
The following example demonstrates creating a table in an external directory using theDATA DIRECTORY clause. It is assumed that theinnodb_file_per_table variable is enabled and that the directory is known toInnoDB.
mysql> USE test;Database changedmysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/external/directory';# MySQL creates the table's data file in a schema directory# under the external directory$> cd /external/directory/test$> lst1.ibdUsage Notes:
MySQL initially holds the tablespace data file open, preventing you from dismounting the device, but might eventually close the file if the server is busy. Be careful not to accidentally dismount an external device while MySQL is running, or start MySQL while the device is disconnected. Attempting to access a table when the associated data file is missing causes a serious error that requires a server restart.
A server restart might fail if the data file is not found at the expected path. In this case, you can restore the tablespace data file from a backup or drop the table to remove the information about it from thedata dictionary.
Before placing a table on an NFS-mounted volume, review potential issues outlined inUsing NFS with MySQL.
If using an LVM snapshot, file copy, or other file-based mechanism to back up the table's data file, always use the
FLUSH TABLES ... FOR EXPORTstatement first to ensure that all changes buffered in memory areflushed to disk before the backup occurs.Using the
DATA DIRECTORYclause to create a table in an external directory is an alternative to usingsymbolic links, whichInnoDBdoes not support.The
DATA DIRECTORYclause is not supported in a replication environment where the source and replica reside on the same host. TheDATA DIRECTORYclause requires a full directory path. Replicating the path in this case would cause the source and replica to create the table in same location.Tables created in file-per-table tablespaces cannot be created in the undo tablespace directory (
innodb_undo_directory) unless that directly is known toInnoDB. Known directories are those defined by thedatadir,innodb_data_home_dir, andinnodb_directoriesvariables.
CREATE TABLE ... TABLESPACE syntax can be used in combination with theDATA DIRECTORY clause to create a table in an external directory. To do so, specifyinnodb_file_per_table as the tablespace name.
mysql> CREATE TABLE t2 (c1 INT PRIMARY KEY) TABLESPACE = innodb_file_per_table DATA DIRECTORY = '/external/directory'; This method is supported only for tables created in file-per-table tablespaces, but does not require theinnodb_file_per_table variable to be enabled. In all other respects, this method is equivalent to theCREATE TABLE ... DATA DIRECTORY method described above. The same usage notes apply.
You can create a table in a general tablespace that resides in an external directory.
For information about creating a general tablespace in an external directory, seeCreating a General Tablespace.
For information about creating a table in a general tablespace, seeAdding Tables to a General Tablespace.
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb