全文検索したいからMacPortsでMySQL5.5とmroongaをインストール…make失敗…orz…となったけどなんとか入った

全文検索したいからMacPortsでMySQL5.5とmroongaをインストール…make失敗…orz…となったけどなんとか入った

※一番下の追記にありますが、Homebrewでインストールできるようになってます(2012/5/29リリース)

MySQL5.5のインストール

MANPでMySQL使えるんだけど、mroongaを(ローカルテストでも)使いたいので別にMySQLをインストールする。

ただしMySQLのバージョンは5.5をインストールしたいのでコマンドはこんな感じに。
mysql5 +server としてしまうとMySQL5.1.6が入ります。

MacBook:~ clicktx$ sudo port install mysql55 +server
Password:
--->  Deactivating mysql55 @5.5.23_0
--->  Cleaning mysql55
--->  Uninstalling mysql55 @5.5.23_0
--->  Cleaning mysql55
MacBook:~ clicktx$ sudo port install mysql55 +server
--->  Computing dependencies for mysql55
--->  Fetching archive for mysql55
--->  Attempting to fetch mysql55-5.5.23_0.darwin_10.x86_64.tbz2 from http://packages.macports.org/mysql55
--->  Fetching mysql55
--->  Verifying checksum(s) for mysql55
--->  Extracting mysql55
--->  Applying patches to mysql55
--->  Configuring mysql55
--->  Building mysql55
--->  Staging mysql55 into destroot
--->  Installing mysql55 @5.5.23_0
The mysql55 client has been installed.
To install the mysql55 server, install the mysql55-server port.
--->  Activating mysql55 @5.5.23_0
--->  Cleaning mysql55

MySQLの初期化

  • mac OSXの場合はmysqlユーザーは作成済みなので改めて作成する必要はない。
  • 実際は_mysql?mysqlでユーザー指定しても_mysqlで処理される。
MacBook:~ clicktx$ sudo -u mysql /opt/local/lib/mysql55/scripts/mysql_install_db
Password:
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql55/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql55/bin/mysqladmin -u root -h MacBook.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql55/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql55/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql55/bin/mysqlbug script!

MySQLを起動する

MacBook:~ clicktx$ sudo /opt/local/share/mysql55/support-files/mysql.server start
Starting MySQL
... ERROR! The server quit without updating PID file (/opt/local/var/db/mysql55/MacBook.local.pid).

そのまま起動すると上記のようにエラーとなってしまう(自分の環境だけ?)

デフォルトでは /opt/local/var/run/mysql55 以下にソケットファイルを作成するらしく、フォルダが無いので作成する。アクセス権も777を与える。

MacBook:~ clicktx$ sudo mkdir -m 777 -p /opt/local/var/run/mysql55

改めてMySQLを起動。

MacBook:~ clicktx$ sudo /opt/local/share/mysql55/support-files/mysql.server start
Starting MySQL
.. SUCCESS! 

成功

参考:

  • Mac OS X に MacPorts で MySQL をインストールする - make world
  • MacPortsを使ってMySQL 5をインストールする - めも帖
  • mroongaのインストール

    2. インストールガイド — mroonga v2.02 documentation

    2.11.3. 前提条件
    MySQLおよびgroongaが既にインストールされている必要があります。
    またmroongaをビルドするためにはMySQLのソースコードも必要です。

    先日groongaはインストール済み。

    先程MacPortsでインストールしたMySQLのでソースは
    /opt/local/var/macports/distfiles/mysql55/mysql-5.5.23.tar.gz
    かな?

    作業スペースを~/src にする。
    まずは作業スペースとなるsrcフォルダを作成。

    MacBook:~ clicktx$ mkdir ~/src

    MySQLのソースファイルを ~/src にコピーして解凍する

    MacBook:~ clicktx$ cp /opt/local/var/macports/distfiles/mysql55/mysql-5.5.23.tar.gz ~/src/mysql-5.5.23.tar.gz
    MacBook:~ clicktx$ cd src/
    MacBook:~ clicktx$ tar xzvf mysql-5.5.23.tar.gz

    mroongaをダウンロード&解凍

    MacBook:src clicktx$ wget http://cloud.github.com/downloads/mroonga/mroonga/mroonga-2.02.tar.gz
    MacBook:src clicktx$ tar xzvf mroonga-2.02.tar.gz 
    

    mroongaをビルドする

    MacBook:src clicktx$ cd mroonga-2.02
    MacBook:mroonga-2.02 clicktx$ ./configure PKG_CONFIG_PATH=/opt/local/lib/pkgconfig --with-mysql-source=$HOME/src/mysql-5.5.23 --with-mysql-config=/opt/local/lib/mysql55/bin/mysql_config
    MacBook:mroonga-2.02 clicktx$ make

    makeでコケる...
    googleで漁っているとこんなの発見。
    installing mroonga on Mac OS X Lion — Gist
    早速試してみる。

    MacBook:~ clicktx$ cd ~/src/mysql-5.5.23/include
    MacBook:include clicktx$ ln -s probes_mysql_nodtrace.h probes_mysql_dtrace.h
    MacBook:include clicktx$ cd ~/src/mroonga-2.02
    MacBook:mroonga-2.02 clicktx$ aclocal -I /opt/local/share/aclocal
    MacBook:mroonga-2.02 clicktx$ automake -a
    MacBook:mroonga-2.02 clicktx$ autoconf
    MacBook:mroonga-2.02 clicktx$ autoheader
    MacBook:mroonga-2.02 clicktx$ automake -a
    MacBook:mroonga-2.02 clicktx$ ./configure PKG_CONFIG_PATH=/opt/local/lib/pkgconfig --with-mysql-source=$HOME/src/mysql-5.5.23 --with-mysql-config=/opt/local/lib/mysql55/bin/mysql_config --with-mecab
    MacBook:mroonga-2.02 clicktx$ make

    コケる...

    mroongaをMac OSXでビルドするためのアドホックなパッチを書いてみた « いわぶろ(ろてん)
    ココらへんに解決策?もう神頼み。
    https://gist.github.com/1015079 を参考に、~/src/mroonga-2.02/ha_mroonga.cpp っていうファイルの560行目付近に

    static_cast(static_cast(pthread_self())),

    っていう箇所があるから、

    static_cast(static_cast((unsigned long int)pthread_self())),

    に修正。
    pthread_self で検索すると修正箇所がすぐ分かる。

    修正した後にmakeしたら見事成功。

    MacBook:mroonga-2.02 clicktx$ sudo make install
    .....
    libtool: install: ranlib /opt/local/lib/mysql55/plugin/ha_groonga.a

    インストールできたぽい。

    公式ガイドに

    その後、mysqldを起動し、mysqlクライアントで接続して"INSTALL PLUGIN"コマンドでインストールします。

    とあるので、MySQL起動してインストール&確認。

    MacBook:~ clicktx$ sudo /opt/local/share/mysql55/support-files/mysql.server start
    MacBook:~ clicktx$ /opt/local/lib/mysql55/bin/mysql -u root
    mysql> INSTALL PLUGIN mroonga SONAME 'ha_mroonga.so';
    Query OK, 0 rows affected (0.48 sec)
    
    mysql> SHOW ENGINES;
    +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
    | Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
    +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
    | CSV                | YES     | CSV storage engine                                         | NO           | NO   | NO         |
    | PERFORMANCE_SCHEMA | YES     | Performance Schema                                         | NO           | NO   | NO         |
    | InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
    | MyISAM             | YES     | MyISAM storage engine                                      | NO           | NO   | NO         |
    | MRG_MYISAM         | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
    | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
    | mroonga            | YES     | CJK-ready fulltext search, column store                    | NO           | NO   | NO         |
    +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
    7 rows in set (0.00 sec)

    なんとか入ったみたい。
    苦労した...。

    なお参考ブログに

    なお,MySQLへの組み込み後の動作については,何も確認を行っていないのであしからず,です.(影響があるとしても,ログ出力部分だけ?)

    とあるように、とりあえずmake出来て、インストールまでこぎつけたってシロモノです。

    追記:2012/6/2
    エラーが出た時にはこちらが参考になります。
    MySQL の INSTALL PLUGIN に失敗する時の処方箋(mroonga-1.20編) - よし研 -日々クリエイション-

    また、mroongaはHomebrewでインストールできるようになったみたいです。こちらの方が簡単でしょう。MacPorts使っているボクは負けg(ry
    mroonga 2.03リリース