Chat (Lingr.com)
Informaiton
Daily
Column
- MySQL日本語の旅(5/1)
- アクセス向上秘伝(5/9)
- 一風変ったHaskellλ門(6/13)
- SICP Answer Book (5/31) 問題3.26追加
Zope Solution
Extra
アーカイブ
OSS案内所
Site Info
関連リンク
英文のオンラインマニュアルと悪戦苦闘していたら、 15.6.6. Using Per-Table Tablespaces を捜し当てた。
詳しくはマニュアルを見て欲しいが、その一部を以下に載せておく。 訳すとミスしそうなので、訳はやめておくので、各自で読んで欲しい。
In MySQL 5.0, you can store each InnoDB table and its indexes in its own file. This feature is called “multiple tablespaces” because in effect each table has its own tablespace. Using multiple tablespaces can be beneficial to users who want to move specific tables to separate physical disks or who wish to restore backups of single tables quickly without interrupting the use of the remaining InnoDB tables. You can enable multiple tablespaces by adding this line to the [mysqld] section of my.cnf: [mysqld] innodb_file_per_table After restarting the server, InnoDB stores each newly created table into its own file tbl_name.ibd in the database directory where the table belongs. This is similar to what the MyISAM storage engine does, but MyISAM divides the table into a data file tbl_name.MYD and the index file tbl_name.MYI. For InnoDB, the data and the indexes are stored together in the .ibd file. The tbl_name.frm file is still created as usual. If you remove the innodb_file_per_table line from my.cnf and restart the server, InnoDB creates tables inside the shared tablespace files again. innodb_file_per_table affects only table creation. If you start the server with this option, new tables are created using .ibd files, but you can still access tables that exist in the shared tablespace. If you remove the option, new tables are created in the shared tablespace, but you can still access any tables that were created using multiple tablespaces.
結局、innodb_file_per_table の真偽値(宣言されているかどうか)により、 InnoDBのデータテーブルが、テーブル毎になったり、 シェアードテーブルスペース(共有)になったりするとのこと。
とりあえず、現状の innodb_file_per_table の値を見ておこう。
mysql> SHOW VARIABLES LIKE 'innodb_file_per_table'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_file_per_table | OFF | +-----------------------+-------+ 1 row in set (0.00 sec)
確かにOFFになっているので、テーブル毎にはならないことと対応している。
一旦サーバを止めて、/etc/my.cnf の mysqldセクションに innodb_file_per_table を追加しよう。
[mysqld] innodb_file_per_table
そして、再びサーバを起動して、
mysql> SHOW VARIABLES LIKE 'innodb_file_per_table'; +-----------------------+-------+ | Variable_name | Value | +-----------------------+-------+ | innodb_file_per_table | ON | +-----------------------+-------+ 1 row in set (0.04 sec) mysql>
となり、テーブル毎にデータを作れそうだ。現状は
shell# cd /usr/local/mysql/var/日本 shell# ls db.opt コピー.MYI 漢字.frm 都道府県.MYI コピー.MYD コピー.frm 都道府県.MYD 都道府県.frm shell#
であるが、一旦 漢字テーブルを消してから、作り直してみよう。
mysql> CREATE TABLE `漢字` ( `字` char(1), `画数` int )
-> ENGINE=InnoDB DEFAULT CHARACTER SET eucjpms;
Query OK, 0 rows affected (0.10 sec)
mysql> INSERT INTO `漢字` VALUES ('鰯',21),('鯰',19),('鰹',23);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
ここで、どういう風にファイルが作られたか見てみよう。
shell# ls db.opt コピー.MYI 漢字.frm 都道府県.MYD 都道府県.frm コピー.MYD コピー.frm 漢字.ibd 都道府県.MYI shell# ls -l 漢字.* -rw-rw---- 1 mysql mysql 8592 10月 16 20:00 漢字.frm -rw-rw---- 1 mysql mysql 98304 10月 16 20:00 漢字.ibd shell#
InnoDBのときと同じように、フォーマットファイルと同じ場所に、 データファイル 漢字.ibd ができた。
InnoDBの場合 (innodb_file_per_table が ON のとき)
テーブル名.frm テーブル定義が記述されているファイル
テーブル名.ibd データおよびインデックスを保存するファイル
これで、この2つのファイルをバックアップしたりコピーすることで、 テーブルのバックアップやコピーができることに筈である。
フィードバック: