MacPorts で MySQL5.5 を入れる

新しい Mac を買ったので環境を再構築。


MacPorts*1 で MySQL5.5 を入れようとしてハマったのでメモ。

$ sudo port install mysql55 +openssl +system_readline
--->  Computing dependencies for mysql55
--->  Fetching archive for mysql55
--->  Attempting to fetch mysql55-5.5.27_0+openssl+system_readline.darwin_12.x86_64.tbz2 from http://packages.macports.org/mysql55
--->  Attempting to fetch mysql55-5.5.27_0+openssl+system_readline.darwin_12.x86_64.tbz2 from http://macports.packages.ionic.de/mysql55
--->  Fetching distfiles for mysql55
--->  Verifying checksum(s) for mysql55
--->  Extracting mysql55
--->  Applying patches to mysql55
--->  Configuring mysql55
--->  Building mysql55
--->  Staging mysql55 into destroot
--->  Installing mysql55 @5.5.27_0+openssl+system_readline
The mysql55 client has been installed.
To install the mysql55 server, install the mysql55-server port.
--->  Activating mysql55 @5.5.27_0+openssl+system_readline
--->  Cleaning mysql55
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
$ sudo port install mysql55-server
--->  Computing dependencies for mysql55-server
--->  Fetching archive for mysql55-server
--->  Attempting to fetch mysql55-server-5.5.27_0.darwin_12.noarch.tbz2 from http://packages.macports.org/mysql55-server
--->  Attempting to fetch mysql55-server-5.5.27_0.darwin_12.noarch.tbz2 from http://macports.packages.ionic.de/mysql55-server
--->  Fetching distfiles for mysql55-server
--->  Verifying checksum(s) for mysql55-server
--->  Extracting mysql55-server
--->  Configuring mysql55-server
--->  Building mysql55-server
--->  Staging mysql55-server into destroot
--->  Creating launchd control script
###########################################################
# A startup item has been generated that will aid in
# starting mysql55-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql55-server
###########################################################
--->  Installing mysql55-server @5.5.27_0
--->  Activating mysql55-server @5.5.27_0

If this is a new install you might want to run:

$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db

--->  Cleaning mysql55-server
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db

を実行しろと表示されているが、これをそのまま実行すると…

$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Installing MySQL system tables...
ERROR: 1005  Can't create table 'tmp_db' (errno: 13)
120814 21:38:26 [ERROR] Aborting

120814 21:38:26 [Note] /opt/local/lib/mysql55/bin/mysqld: Shutdown complete


Installation of system tables failed!  Examine the logs in
/opt/local/var/db/mysql55 for more information.

You can try to start the mysqld daemon with:

    shell> /opt/local/lib/mysql55/bin/mysqld --skip-grant &

and use the command line tool /opt/local/lib/mysql55/bin/mysql
to connect to the mysql database and look at the grant tables:

    shell> /opt/local/lib/mysql55/bin/mysql -u root mysql
    mysql> show tables

Try 'mysqld --help' if you have problems with paths.  Using --log
gives you a log in /opt/local/var/db/mysql55 that may be helpful.

Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS.  Another information source are the
MySQL email archives available at http://lists.mysql.com/.

Please check all of the above before mailing us!  And remember, if
you do mail us, you MUST use the /opt/local/lib/mysql55/bin/mysqlbug script!

とかって言われてエラーになる。

$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db --tmpdir=/tmp
Installing MySQL system tables...
OK
Filling help tables...
OK
- 略 -

と --tmpdir をつけると行けた。


後は

$ sudo port load mysql55-server
$ sudo port select mysql mysql55
Selecting 'mysql55' for 'mysql' succeeded. 'mysql55' is now active.

とかして MySQL を起動して、mysql コマンドを使えるようにする。

*1:homebrew? /usr 領域を汚すので嫌だから使ってない