14.7.5 Creating File-Per-Table Tablespaces Outside

To create a file-per-table tablespace in a location outside the MySQL data directory, use the DATA DIRECTORY =absolute_path_to_directory clause of the CREATE TABLE statement.
要在MySQL數據目錄之外的位置創建 file-per-table表空間,請使用 CREATE TABLE 語句的DATA DIRECTORY =absolute_path_to_directory 子句。
Plan the location in advance, because you cannot use the DATA DIRECTORY clause with the ALTER TABLE statement to change the location later. 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 HDD.
事先規劃位置,因爲您不能將ALTER TABLE語句中的DATA DIRECTORY子句用於稍後更改位置。您指定的目錄可能位於具有特定性能或容量特性的其他存儲設備上,如快速SSD或高容量HDD。
Within the target 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 a table_name.isl 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 InnoDB tables.)
在目標目錄中,MySQL創建一個與數據庫名相對應的子目錄,並在其中創建新表的.ibd文件。 在MySQL DATADIR目錄下的數據庫目錄中,MySQL創建一個table_name.isl文件,其中包含表的路徑名。.isl文件被MySQL視爲符號鏈接。 (使用實際的符號鏈接從未被InnoDB表支持。)
The following example demonstrates creating a file-per-table tablespace outside the MySQL data directory. It shows the.ibd file created in the specified directory, and the .isl file created in the database directory beneath the MySQL data directory.
以下示例演示了在MySQL數據目錄之外創建一個file-per-tabl 的表空間。它顯示在指定目錄中創建的.ibd文件以及在MySQL數據目錄下的數據庫目錄中創建的.isl文件。
mysql> USE test;
Database changed

mysql> SHOW VARIABLES LIKE 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+

mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY) DATA DIRECTORY = '/alternative/directory';

#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
You can also use CREATE TABLE ... TABLESPACE in combination with the DATA 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 ... TABLESPACE與DATA DIRECTORY子句結合使用,在MySQL數據目錄之外創建一個file-per-table 表空間。 爲此,您必須指定innodb_file_per_table作爲表空間名稱。
mysql> 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 this method.
使用此方法時,您不必啓用innodb_file_per_table。
Usage Notes:

使用說明

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 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 .ibd file is still not at the expected path. In this case, manually remove the table_name.isl 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 dictionary.

  • MySQL最初保持.ibd文件打開,防止您卸載該設備,但如果服務器繁忙,可能最終關閉該表。小心不要在MySQL運行時意外卸載外部設備,或者在設備斷開連接時啓動MySQL.當關聯的.ibd文件丟失時,試圖訪問表會導致嚴重的錯誤,需要重新啓動服務器。
  • 如果.ibd文件仍然不在預期路徑中,服務器重新啓動可能會失敗。 在這種情況下,請手動刪除數據庫目錄中的table_name.isl文件,重新啓動後執行DROP TABLE以刪除.frm文件並從數據字典中刪除有關該表的信息。
  • Before placing tables on an NFS-mounted volume, review potential issues outlined in Using NFS with MySQL.
  • 在將表放置在安裝了NFS的捲上之前,請查看Using NFS with MySQL.概述的潛在問題。
  • If you use an LVM snapshot, file copy, or other file-based mechanism to back up the .ibd file, always use the FLUSH TABLES ... FOR EXPORT statement first to make sure that all changes buffered in memory are flushed to disk before the backup occurs.
  • 如果使用LVM快照,文件副本或其他基於文件的機制來備份.ibd文件,請始終首先使用FLUSH TABLES ... FOR EXPORT語句,以確保確保在備份發生之前將緩衝內存中的所有更改刷新到磁盤。
  • The DATA DIRECTORY clause is a supported alternative to using symbolic links, which is not supported for individual InnoDB tables.
  • DATA DIRECTORY子句是受支持的使用符號鏈接的替代方法,不支持單個InnoDB表。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章