Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yoku0825
Created September 4, 2015 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoku0825/1d78ab50d386c775fa85 to your computer and use it in GitHub Desktop.
Save yoku0825/1d78ab50d386c775fa85 to your computer and use it in GitHub Desktop.
  • mroonga1というデータベースとmroonga2というデータベースを作ります。
  • mroonga1.table1というテーブルとmroonga2.table2というテーブルを作ります。
mysql> CREATE DATABASE mroonga1;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE TABLE mroonga1.table1 (num serial, val varchar(32)) Engine= Mroonga;
Query OK, 0 rows affected (0.09 sec)

mysql> CREATE DATABASE mroonga2;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE TABLE mroonga2.table2 (num serial, val varchar(32)) Engine= Mroonga;
Query OK, 0 rows affected (0.10 sec)
  • この時、MySQLのデータディレクトリにはこんな配置がされます。
$ ll
total 110804
-rw-rw---- 1 mysql mysql       56 Sep  4 19:27 auto.cnf
-rw-rw---- 1 mysql mysql     5846 Sep  4 19:32 groonga.log
-rw-rw---- 1 mysql mysql 12582912 Sep  4 19:31 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Sep  4 19:32 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Sep  4 19:27 ib_logfile1
drwx------ 2 mysql mysql     4096 Sep  4 19:32 mroonga1
-rw-r----- 1 mysql mysql     4096 Sep  4 19:32 mroonga1.mrn
-rw-r----- 1 mysql mysql 12857344 Sep  4 19:32 mroonga1.mrn.0000000
-rw-r----- 1 mysql mysql  4243456 Sep  4 19:32 mroonga1.mrn.0000105
-rw-r----- 1 mysql mysql     4096 Sep  4 19:32 mroonga1.mrn.0000106
-rw-r----- 1 mysql mysql   274432 Sep  4 19:32 mroonga1.mrn.0000107
-rw-r----- 1 mysql mysql  1048576 Sep  4 19:32 mroonga1.mrn.001
drwx------ 2 mysql mysql     4096 Sep  4 19:32 mroonga2
-rw-r----- 1 mysql mysql     4096 Sep  4 19:32 mroonga2.mrn
-rw-r----- 1 mysql mysql 12857344 Sep  4 19:32 mroonga2.mrn.0000000
-rw-r----- 1 mysql mysql  4243456 Sep  4 19:32 mroonga2.mrn.0000105
-rw-r----- 1 mysql mysql     4096 Sep  4 19:32 mroonga2.mrn.0000106
-rw-r----- 1 mysql mysql   274432 Sep  4 19:32 mroonga2.mrn.0000107
-rw-r----- 1 mysql mysql  1048576 Sep  4 19:32 mroonga2.mrn.001
drwx------ 2 mysql mysql     4096 Sep  4 19:27 mysql
srwxrwxrwx 1 mysql mysql        0 Sep  4 19:31 mysql.sock
drwx------ 2 mysql mysql     4096 Sep  4 19:27 performance_schema
  • mroonga1ディレクトリがMySQLから見たmroonga1データベースです。
  • mroonga1.mrn*がMroongaから見たmroonga1データベースのデータです。
  • mroonga2も同様です。
$ ll mroonga1
total 16
-rw-rw---- 1 mysql mysql   65 Sep  4 19:32 db.opt
-rw-rw---- 1 mysql mysql 8586 Sep  4 19:32 table1.frm

$ ll mroonga2
total 16
-rw-rw---- 1 mysql mysql   65 Sep  4 19:32 db.opt
-rw-rw---- 1 mysql mysql 8586 Sep  4 19:32 table2.frm
  • それぞれのディレクトリ(=MySQLから見たデータベース)の中には、db.optファイル(データベースの属性情報が入っています)とtable1.frm, table2.frmがあります。
  • .frmファイルはテーブルの定義情報(SHOW CREATE TABLEで表示される中身)が入っています。
    • この.frmファイルの中に、「細かいことはMroongaストレージエンジンに聞け」という情報が入っています。
    • MySQLさんがMroongaさんに「mroonga2.table2の情報が欲しいよ!」と話しかけると、Mroongaさんは自分の認識しているdatabase2(=database2.mrn*ファイル群)からデータを引っこ抜いてきて渡します。
$ sudo service mysqld stop
$ rm mroonga1/table1.frm mroonga1.mrn*
$ sudo service mysqld start
mysql> CREATE TABLE mroonga1.table1 (num serial, val varchar(32)) Engine= Mroonga;
Query OK, 0 rows affected (0.10 sec)
  • という訳でデータベース名.mrn*とデータベース名/テーブル名.frmファイルを消すと全てのMroongaのテーブル情報が削除され、最初に戻ることができます。
  • ちなみに、mysqldを止めずにこれをやろうとすると、Mroongaさん側の情報がメモリーに残ってしまい、同じ名前のテーブルを作ろうとするとエラーになることがあります。
$ rm mroonga2/table2.frm mroonga2.mrn*
mysql> CREATE TABLE mroonga2.table2 (num serial, val varchar(32)) Engine= Mroonga;
ERROR 1005 (HY000): already used name was assigned: <table2>
  • こうなった場合は再起動してあげてください。
$ sudo service mysqld restart
mysql> CREATE TABLE mroonga2.table2 (num serial, val varchar(32)) Engine= Mroonga;
Query OK, 0 rows affected (0.10 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment