9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ソースからインストールしたMySQLにMroongaをインストール

Last updated at Posted at 2015-09-19

今回の記事では、MySQLにMroongaというストレージエンジンを追加する方法について説明していきます。
ストレージエンジンとは、RDBMSにおいて、データのアクセスや排他制御を行う部分のことをいうようです。こちらの記事に詳しい説明が書いてありました。
以下では、Mroonga追加の手順を説明していきます。

1. groongaのインストール

MySQLにMroongaをインストールするためには、事前にgroongaというものを追加する必要があるようです。そこで、まずgroongaの公式サイトからソースをダウンロードして、インストールを行います。

# wget http://packages.groonga.org/source/groonga/groonga-5.0.7.tar.gz
# tar xzvf groonga-5.0.7.tar.gz
# cd groonga-5.0.7
# ./configure
# make
# porg -lD "make install"

2. groongaのパスを設定

続いて、Mroongaをインストールする際に事前にgroongaのパスを通す必要があるので、ヘッダファイルとライブラリファイルのパスを設定します。

# export GROONGA_CFLAGS="-I/usr/local/include/groonga"
# export GROONGA_LIBS="-L/usr/local/lib -lgroonga"
こっちのほうが良いらしい
# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

3. Mroongaのインストール

次に、Mroongaのインストールを行います。インストールの際のオプションとして、--with-mysql-sourceにソースファイルのパス、--with-mysql-buildにビルドしたファイルのパス、--with-mysql-configにconfigファイルのパスを指定します。

# wget http://packages.groonga.org/source/mroonga/mroonga-5.06.tar.gz
# tar xzvf mroonga-5.06.tar.gz 
# cd mroonga-5.06
# ./configure --with-mysql-source=/usr/local/src/mysql-5.6.25 --with-mysql-build=/usr/local/src/mysql-5.6.25 --with-mysql-config=/usr/local/mysql/bin/mysql_config
# make
# porg -lD "make install"

4. MySQLの再起動

インストールしたMroongaのファイルをMySQLに反映させるため、MySQLを再起動します。

# service mysqld restart

5. MySQLにMroongaを追加

Mroongaのインストールが完了後、MySQLを起動し、Mroongaをストレージエンジンとして、追加します。show enginesコマンドでMroongaが追加されていればインストールは完了です。

# mysql -u ****
mysql> install plugin mroonga soname 'ha_mroonga.so';
Query OK, 0 rows affected (0.39 sec)

mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| Mroonga            | YES     | CJK-ready fulltext search, column store                        | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
10 rows in set (0.00 sec)

mysql> show variables like 'mroonga_version';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| mroonga_version | 5.06  |
+-----------------+-------+

6. Mroongaの利用方法

最後にMroongaが利用可能か確認するため、以下のようなSQL文を入力し、**SELECT * FROM diaries WHERE MATCH(content) AGAINST("fine");で、出力結果としてIt'll be fine tomorrow.**のレコードが返ってくいれば、全文検索を利用することができています。

// テーブルの作成
mysql> CREATE TABLE diaries (
    ->   id INT PRIMARY KEY AUTO_INCREMENT,
    ->   content VARCHAR(255),
    ->   FULLTEXT INDEX (content)  // ここがポイント
    -> ) ENGINE = Mroonga DEFAULT CHARSET utf8;  // ここがポイント

// データの挿入
mysql> INSERT INTO diaries (content) VALUES ("It'll be fine tomorrow.");

// データの全文検索の実行
mysql> SELECT * FROM diaries WHERE MATCH(content) AGAINST("fine");
+----+-----------------------------------------+
| id | content                                 |
+----+-----------------------------------------+
|  1 | It'll be fine tomorrow. |
+----+-----------------------------------------+

参考文献

  1. [ThinkIT] 第1回:MySQLストレージエンジンの概要 (1_3), http://thinkit.co.jp/free/article/0608/1/1/, Online; accessed 15-September-2015.
  2. 2.5. CentOS — Groonga v5.0.7ドキュメント, http://groonga.org/ja/docs/install/centos.html#build-from-source, Online; accessed 11-September-2015.
  3. Mac に Groonga_Mroonga 3.0.0 を homebrew でインストールする際にはまったこと - aki note, http://d.hatena.ne.jp/akipponn3/20130220/1361371858, Online; accessed 11-September-2015.
  4. 2.7. その他 — Mroonga v5.06 documentation, http://mroonga.org/ja/docs/install/others.html#build-from-source, Online; accessed 11-September-2015.
  5. 4.1. インストールチェック — Mroonga v5.06 documentation, http://mroonga.org/ja/docs/tutorial/installation_check.html, Online; accessed 11-September-2015.
  6. 4.3. ストレージモード — Mroonga v5.06 documentation, http://mroonga.org/ja/docs/tutorial/storage.html#how-to-use-full-text-search, Online; accessed 11-September-2015.
9
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?