Open Source WEB

英文のオンラインマニュアルと悪戦苦闘していたら、 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つのファイルをバックアップしたりコピーすることで、 テーブルのバックアップやコピーができることに筈である。


戻る:InnoDBのデータファイルは何処にあるのか

次へ:テーブルがHEAPの場合はどうなるか


フィードバック:

Name:
Comment:
城: (Wed Feb 8 11:30:00 2006 )
http://dev.mysql.com/doc/refman/4.1/ja/multiple-tablespaces.html
http://dev.mysql.com/doc/refman/5.1/en/multiple-tablespaces.html
こちらに、
「You cannot freely move .ibd files between database directories as you can with MyISAM table files. 」
とあるのでバックアップに使えないのではないでしょうか?
城: (Wed Feb 8 11:34:41 2006 )
すみません2重投稿になってしまいました。

あとバックアップの件ですが、
If you have a “clean” backup of an .ibd file, you can restore .....
でどうやら可能らしいです。
早とちりしてすみません。
城: (Wed Feb 8 11:44:59 2006 )
2重投稿になってしまうバグがあるのではないでしょうか?
環境は win xp sp2 / ie 6 / cookie許可 / java script 許可 / セキュリティソフトなし
です。一度見てみてください
Themba: (Sat Feb 18 14:34:46 2012 )
There's a secert about your post. ICTYBTIHTKY

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us