1. 程式人生 > >mysql官方手冊對 Using Per-Table Tablespaces 的說明

mysql官方手冊對 Using Per-Table Tablespaces 的說明

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.

Advantages
of Per-Table Tablespaces

  • You can reclaim disk space when truncating or dropping a table. For tables created when file-per-table mode is turned off, truncating or dropping them creates free space internally in the ibdata files. That free space can only be used for new InnoDB data.

  • The TRUNCATE TABLE

     operation is faster when run on individual .ibd files.

  • You can store specific tables on separate storage devices, for I/O optimization, space management, or backup purposes.

  • You can run OPTIMIZE TABLE to compact or recreate a tablespace. When you run an OPTIMIZE TABLEInnoDBwill create a new .ibd

     file with a temporary name, using only the space required to store actual data. When the optimization is complete, InnoDB removes the old .ibd file and replaces it with the new .ibd file. If the previous.ibd file had grown significantly but actual data only accounted for a portion of its size, running OPTIMIZE TABLEallows you to reclaim the unused space.

  • You can move individual InnoDB tables rather than entire databases.

  • 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.

  • If innodb_file_per_table is disabled, there is one shared tablespace (the system tablespace) for tables, the data dictionary, and undo logs. This single tablespace has a 64TB size limit. If innodb_file_per_table is enabled, each table has its own tablespace, each with a 64TB size limit. See Section E.10.3, “Limits on Table Size”for related information.

Enabling and Disabling Multiple Tablespaces

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 tbl_name.ibd file in the appropriate database directory. Unlike the MyISAM storage engine, with its separate tbl_name.MYD andtbl_name.MYI files for indexes and data, InnoDB stores the data and the indexes together in a single .ibd file. The tbl_name.frm file is still created as usual.

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 oninnodb_file_per_table and then recreate the entire instance using the mysqldumpcommand.(Innodb table這樣使用起來非常不方便)