気付けばPHPとMySQLのコンパイルオプションが変わっていたでござるの巻

こんにちは!僕です!
MySQL5.5がGAになってから5ヶ月近くが経ち、テスト環境構築を兼ねて現時点の最新版をインストールすることにしました。

まず現時点で最新のMySQLをダウンロード

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.11.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
$ tar zfx mysql-5.5.11.tar.gz
$ ./configure

  • bash: ./configure: そのようなファイルやディレクトリはありません

ってあれ?configureが通らないの???


とりあえずconfigファイルの中身を確認しようとディレクトリの中身を調べると

-rw-r--r-- 1 7161 wheel 8479 3月 31 22:36 BUILD-CMAKE

CMAKE?
BUILD-CMAKEの中を読むとわかるが、MySQL5.5からビルドがconfigureからcmakeになったんですね。
しかもさらに調べるとコンパイルオプションも全然変わってるようで、比較的よく使うオプションはこうなる

--prefix=/usr/local/mysql/ → -DCMAKE_INSTALL_PREFIX=/usr/local/mysql

    • localstatedir=/usr/local/mysql/data → -DMYSQL_DATADIR=/usr/local/mysql/data
    • with-tcp-port=3306 → -DMYSQL_TCP_PORT=3306

その他のオプションについてはマニュアルをご参考ください。

ということで、cmakeが無い場合はコンパイルしてcmakeするとうまくいきます。

$ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
$ make
$ sudo make install

mysql_install_dbはパスが通ってないのか、ファイルがあるディレクトリに行かないとうまく動いてくれない。

# cd /usr/local/mysql/scripts/
# ./mysql_install_db

うまくいったら起動しましょう。

/usr/local/mysql/support-files/mysql.server start

mysql> show engines;

  1. --------------------+---------+------------------------------------------------------------+--------------+------+------------+
Engine Support Comment Transactions XA Savepoints
  1. --------------------+---------+------------------------------------------------------------+--------------+------+------------+
MRG_MYISAM YES Collection of identical MyISAM tables NO NO NO
PERFORMANCE_SCHEMA YES Performance Schema NO NO NO
MyISAM YES MyISAM storage engine NO NO NO
InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES
CSV YES CSV storage engine NO NO NO
MEMORY YES Hash based, stored in memory, useful for temporary tables NO NO NO
  1. --------------------+---------+------------------------------------------------------------+--------------+------+------------+

InnoDBがデフォルトストレージエンジンに変更されてます。

mysql> select @@innodb_version;

  1. ------------------+
@@innodb_version
  1. ------------------+
1.1.5
  1. ------------------+

innodbプラグインもデフォルトで搭載


どうにかMySQLが入ったので、次にPHP5.3.6をインストール


$ ./configure --prefix=/usr/local/php \
      --with-apxs2=/usr/bin/apxs \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-pdo-mysql=/usr/local/mysql/bin/mysql_config
こちらはさすがにcmakeってことはないよね。





・・・あら?エラー?

checking for mysql_set_server_option in -lmysqlclient... no
configure: error: wrong mysql library version or lib not found. Check config.log for more information.

mysqlライブラリがないだとぅ?
調べてみると

$ ll /usr/local/mysql/bin/mysql_config

  • rwxr-xr-x 1 root root 6924 3月 31 22:58 /usr/local/mysql/bin/mysql_config

ちゃんと存在してるわ!

心が病みつつhelpを読む

$ ./configure --help | grep mysql
--with-mysql[=DIR] Include MySQL support. DIR is the MySQL base
directory. If mysqlnd is passed as DIR,
--with-mysql-sock[=DIR] MySQL/MySQLi/PDO_MYSQL: Location of the MySQL unix socket pointer.
--with-mysqli[=FILE] Include MySQLi support. FILE is the path
to mysql_config. If mysqlnd is passed as FILE,
the MySQL native driver will be used [mysql_config]
--enable-embedded-mysqli MYSQLi: Enable embedded support
--with-pdo-mysql[=DIR] PDO: MySQL support. DIR is the MySQL base directory
If mysqlnd is passed as DIR, the MySQL native
--disable-mysqlnd-compression-support
Enable support for the MySQL compressed protocol in mysqlnd
--with-zlib-dir[=DIR] mysqlnd: Set the path to libz install prefix

ほうほう。
どうやらphp5.3系からはmysqlndというネイティブmysqlドライバが搭載されたようで、mysqlを使う場合は

--with-mysqli=[MySQLのベースディレクトリ]

    • with-mysqli=mysqlnd

どちらかでいけるらしい。
mysql_configを指定してるのに入れてくれないのは何故かわからないが、とりあえずネイティブドライバを使うことにする。


$ ./configure --prefix=/usr/local/php \
      --with-apxs2=/usr/bin/apxs \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd

+--------------------------------------------------------------------+

License:
This software is subject to the PHP License, available in this
distribution in the file LICENSE. By continuing this installation
process, you are bound by the terms of this license agreement.
If you do not agree with the terms of this license, you must abort
the installation process at this point.
  1. --------------------------------------------------------------------+

今度はちゃんと通った。

あとは普通にmakeしてインストール


# make
# make install

ネイティブドライバが入った
20110426_94550.jpg

いちおうこれでコンパイルは通ったわけだけど、mysqliやmysqlpdoと全く同等にmysqlndが使えるのかどうかはこれから検証します。

とりあえず今回の作業で、毎日同じことだけ繰り返してると、いつの間にか周りに取り残されることだけは判りました(汗