フルテキストサーチのプラグインとして優秀なmoroongaをmariadbと一緒に入れる方法です。
WSL上のUbuntu18.04にmoroongaとともにmariadbをインストールしたのでその時のメモ。
事前準備
にあるように、リポジトリを追加しておく。
% sudo apt-get install -y -V software-properties-common lsb-release
% sudo add-apt-repository -y universe
% sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu $(lsb_release --short --codename)-security main restricted"
% sudo add-apt-repository -y ppa:groonga/ppa
% sudo apt-get update
moroongaとセットでインストールできるパッケージを探す
# apt list -a | grep mariadb
mariadb-server-10.1-mroonga
というパッケージがあった。2021/04/02時点では、手なりでmariadbを入れると、mariadb-server-10.5
が入っちゃうので、明示的にバージョン指定をしてインストールする必要がある。
# apt install mariadb-server-10.1-mroonga
これでインストールされる。まずは起動。
# service mysql start
mariadbのみをインストールした時には、 service mariadb start
の起動スクリプトでもいけたが、今回のパッケージでは、そのサービス名が登録されていなかった。
次にログイン
# mysql -uroot
これでmoroongaのエンジンが入ってるかなぁと思ってワクワクして、エンジンのリストを見ると…
MariaDB [(none)]> SHOW ENGINES;
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | Stores tables as CSV files | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MyISAM | YES | Non-transactional engine with good performance and small data footprint | NO | NO | NO |
| SEQUENCE | YES | Generated tables filled with sequential values | YES | NO | YES |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
入ってない。
プラグインファイルはインストールされたけど、実際にmariadbには設定されてないみたい。なので、セットアップ用のsqlファイルを手動で流す。
MariaDB [(none)]> source /usr/share/mroonga/install.sql
これで、エンジンはどうなったかなぁと思って確認。
MariaDB [(none)]> SHOW ENGINES;
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| CSV | YES | Stores tables as CSV files | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
| MyISAM | YES | Non-transactional engine with good performance and small data footprint | NO | NO | NO |
| SEQUENCE | YES | Generated tables filled with sequential values | YES | NO | YES |
| Mroonga | YES | CJK-ready fulltext search, column store | NO | NO | NO |
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
| InnoDB | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
+--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
はいった!
せっかくなのでmoroongaのバージョンも確認。
MariaDB [(none)]> SHOW VARIABLES LIKE 'mroonga_version';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| mroonga_version | 10.11 |
+-----------------+-------+
1 row in set (0.00 sec)
嬉しい。
嬉しいポイント
- 普段使いのmysqlに日本語全文検索エンジンがはいる
- mysqlとmariadbの両方にmoroongaは入るので、可搬性が高いmatch構文になる
- mariadbとセットになったパッケージがあるのが嬉しい(mysqlにもmoroongaとセットになったパッケージはある)
- 直接sqlを最期に流さないと行けないのはちょっとしたトラップだが、apt一発でsqlまで流れるのはやりすぎなのでこんな感じでちょうどいい