The innodb_file_per_table
option is enabled by default as of MySQL 5.6.6.
To set the
innodb_file_per_table option at
startup, start the server with the
--innodb_file_per_table
command-line option, or add this line to the
[mysqld] section of
my.cnf:
[mysqld] innodb_file_per_table=1
You can also set
innodb_file_per_table
dynamically, while the server is running:
SET GLOBAL innodb_file_per_table=1;
With innodb_file_per_table
enabled, you can store InnoDB tables in a
file. 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 disable
innodb_file_per_table in your
startup options and restart the server, or disable it with the
SET GLOBAL command, InnoDB
creates new tables inside the system tablespace.
You can always read and write any InnoDB
tables, regardless of the file-per-table setting.
To move a table from the system tablespace to its own
tablespace, change the
innodb_file_per_table setting
and rebuild the table:
SET GLOBAL innodb_file_per_table=1;
ALTER TABLE table_name ENGINE=InnoDB;
InnoDB always needs the system 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 may prefer to enable
innodb_file_per_table and
recreate the entire instance using the
mysqldump command.