[+/-]
By default, all InnoDB tables and indexes are stored in the
system tablespace.
As an alternative, you can store each InnoDB
table and its indexes in its own file. This feature is called
“multiple tablespaces” because each table that is
created when this setting is in effect has its own tablespace.
Using multiple tablespaces is useful in a number of situations:
You can back up or restore a single table quickly without
interrupting the use of other InnoDB
tables, using the MySQL Enterprise Backup product. See
Backing Up and Restoring a Single .ibd File for the procedure
and restrictions.
Storing specific tables on separate physical disks, for I/O optimization or backup purposes.
Restoring backups of single tables quickly without
interrupting the use of other InnoDB
tables.
Using compressed row format to compress table data.
Reclaiming disk space when truncating a table.
To enable multiple tablespaces, start the server with the
--innodb_file_per_table option. For
example, add a line to the [mysqld] section of
my.cnf:
[mysqld] innodb_file_per_table
With multiple tablespaces enabled, InnoDB
stores each newly created table in its own
file
in the appropriate database directory. Unlike the
tbl_name.ibdMyISAM storage engine, with its separate
and
tbl_name.MYD files
for indexes and data, tbl_name.MYIInnoDB stores the data
and the indexes together in a single .ibd
file. The
file
is still created as usual.
tbl_name.frm
If you remove the
innodb_file_per_table line from
my.cnf and restart the server,
InnoDB creates any new tables inside the shared
tablespace files.
You can always access both tables in the system tablespace and
tables in their own tablespaces, regardless of the file-per-table
setting. To move a table from the system tablespace to its own
tablespace, or vice versa, you can change the
innodb_file_per_table setting and
issue the command:
-- Move table from system tablespace to its own tablespace. SET GLOBAL innodb_file_per_table=1; ALTER TABLEtable_nameENGINE=InnoDB; -- Move table from its own tablespace to system tablespace. SET GLOBAL innodb_file_per_table=0; ALTER TABLEtable_nameENGINE=InnoDB;
InnoDB always needs the shared tablespace
because it puts its internal data dictionary and undo logs
there. The .ibd files are not sufficient
for InnoDB to operate.
When a table is moved out of the system tablespace into its own
.ibd file, the data files that make up the
system tablespace remain the same size. The space formerly
occupied by the table can be reused for new
InnoDB data, but is not reclaimed for use by
the operating system. When moving large
InnoDB tables out of the system tablespace,
where disk space is limited, you might prefer to turn on
innodb_file_per_table and then recreate the
entire instance using the mysqldump command.
You cannot freely move .ibd files between
database directories as you can with MyISAM
table files. The table definition stored in the
InnoDB shared tablespace includes the database
name. The transaction IDs and log sequence numbers stored in the
tablespace files also differ between databases.
To move an .ibd file and the associated table
from one database to another, use a RENAME
TABLE statement:
RENAME TABLEdb1.tbl_nameTOdb2.tbl_name;
If you have a “clean” backup of an
.ibd file, you can restore it to the MySQL
installation from which it originated as follows:
The table must not have been dropped or truncated since you
copied the .ibd file, because doing so
changes the table ID stored inside the tablespace.
Issue this ALTER TABLE
statement to delete the current .ibd
file:
ALTER TABLE tbl_name DISCARD TABLESPACE;
Copy the backup .ibd file to the proper
database directory.
Issue this ALTER TABLE
statement to tell InnoDB to use the new
.ibd file for the table:
ALTER TABLE tbl_name IMPORT TABLESPACE;
In this context, a “clean” .ibd
file backup is one for which the following requirements are
satisfied:
There are no uncommitted modifications by transactions in the
.ibd file.
There are no unmerged insert buffer entries in the
.ibd file.
Purge has removed all delete-marked index records from the
.ibd file.
mysqld has flushed all modified pages of
the .ibd file from the buffer pool to the
file.
You can make a clean backup .ibd file using
the following method:
Stop all activity from the mysqld server and commit all transactions.
Wait until SHOW
ENGINE INNODB STATUS shows that there are no active
transactions in the database, and the main thread status of
InnoDB is Waiting for server
activity. Then you can make a copy of the
.ibd file.
Another method for making a clean copy of an
.ibd file is to use the MySQL Enterprise
Backup product:
Use MySQL Enterprise Backup to back up the
InnoDB installation.
Start a second mysqld server on the backup
and let it clean up the .ibd files in the
backup.

User Comments
Add your own comment.