DRY

Web関連の技術の事、食事/お酒の事、旅行の事など

Macにbrewでmysql5.5系をインストールする方法

Macbrewコマンドを用いてmysql5.5系をインストールしたかったのですが、どうにもエラーが出てインストールできず
最新の適切な対応方法が見当たらなかったので、書き留めておきます。

2013/10/22現在の内容です。
現在 brew install mysql を行うとMySQL5.6系がインストールされます。
それをMySQL5.5系にしたいので下記のやり方にてインストールしようとします。


user@pc[/usr/local]$ cd /usr/local
user@pc[/usr/local]$ brew versions mysql
5.6.13 git checkout f60c8fb Library/Formula/mysql.rb
5.6.12 git checkout ed829a3 Library/Formula/mysql.rb
5.6.10 git checkout 48f7e86 Library/Formula/mysql.rb
5.5.29 git checkout 336c976 Library/Formula/mysql.rb
5.5.28 git checkout 5825f62 Library/Formula/mysql.rb
5.5.27 git checkout 93aecfa Library/Formula/mysql.rb
5.5.25a git checkout faaa6c1 Library/Formula/mysql.rb
5.5.25 git checkout 5bcd1f3 Library/Formula/mysql.rb
5.5.24 git checkout a977fbd Library/Formula/mysql.rb
5.5.20 git checkout f4009ef Library/Formula/mysql.rb
5.5.19 git checkout c2b8e87 Library/Formula/mysql.rb
5.5.15 git checkout 513c0f8 Library/Formula/mysql.rb
5.5.14 git checkout a840c4a Library/Formula/mysql.rb
5.5.12 git checkout 35b60ca Library/Formula/mysql.rb
5.5.10 git checkout 1f2b24e Library/Formula/mysql.rb
5.1.56 git checkout feae63a Library/Formula/mysql.rb
5.1.55 git checkout 0476235 Library/Formula/mysql.rb
5.1.54 git checkout 7077f84 Library/Formula/mysql.rb
5.1.53 git checkout fbee3a0 Library/Formula/mysql.rb
5.1.52 git checkout 7871a99 Library/Formula/mysql.rb
5.1.51 git checkout 0fc5ce3 Library/Formula/mysql.rb
5.1.49 git checkout 2e7d624 Library/Formula/mysql.rb
5.1.48 git checkout 75def21 Library/Formula/mysql.rb
5.1.47 git checkout 9d73887 Library/Formula/mysql.rb
5.1.46 git checkout ee9ecec Library/Formula/mysql.rb
5.1.45 git checkout 1ca6b6b Library/Formula/mysql.rb
5.1.44 git checkout 052d1f2 Library/Formula/mysql.rb
5.1.43 git checkout c4decd7 Library/Formula/mysql.rb
user@pc[/usr/local]$ git checkout 336c976 Library/Formula/mysql.rb
user@pc[/usr/local]$ brew install mysql
==> Downloading http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz/from/http://cdn.mysql.com/
curl: (22) The requested URL returned error: 404
Error: Download failed: http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz/from/http://cdn.mysql.com/
exit 1

そうすると上記のようにエラーが出てインストールできません。


user@pc[/usr/local]$ less Library/Formula/mysql.rb
require 'formula'

class Mysql < Formula
homepage 'http://dev.mysql.com/doc/refman/5.5/en/'
url 'http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.29.tar.gz/from/http://cdn.mysql.com/'
version '5.5.29'
sha1 '40e26b193b6ece86ce97896c0c9c524d479e37be'

mysql.rbを見てると確実に5.5.29をダウンロードしようとしているので、コマンド等の間違いでは無さそうです。

いろいろ調べると、現在はMySQL5.6がstableなので5.5系は、途中でHomebrewの対応が終わっているらしい。
それでMySQL5.5.29(以下のバージョンすべてでしたが)のリンクがデッドリンクになっているためダウンロード出来ないらしい。
と言うことみたいでした。

MySQLのサイトに行くと事実現在の5.5系は5.5.34が最新のようです。)

それで下記のgithubアカウントに辿り着いたので
https://github.com/Homebrew/homebrew-versions
ページ下部を見てみると


>How do I install these formulae?
>
>Just brew tap homebrew/versions and then brew install .
>
>If the formula conflicts with one from mxcl/master or another tap, you can brew install homebrew/versions/.
>
>You can also install via URL:
>
>brew install https://raw.github.com/Homebrew/homebrew-versions/master/.rb
このようにを指定してインストールできるようです。

で、リストを眺めると
>mysql55.rb
があるので、中身を確認すると


class Mysql55 < Formula
homepage 'http://dev.mysql.com/doc/refman/5.5/en/'
url 'http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.30.tar.gz'
sha1 'd7e31246d29f6ed4a9c4b966d6896bf920b68351'
どうやら出来そうな気がします。


なので説明文にあった一番下のコマンドでインストールを試みると


user@pc[/usr/local]$ brew install https://raw.github.com/Homebrew/homebrew-versions/master/mysql55.rb
######################################################################## 100.0%
==> Downloading http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.30.tar.gz
######################################################################## 100.0%
==> cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/mysql55/5.5.30 -DMYSQL_DATADIR=/usr/local/var/mysql55 -DINSTALL_MANDIR=/usr/local/Cellar/mysql55/5.5.30/share/man -DINSTALL_DOCDIR=/usr/local/Cella
==> make
==> make install
==> /usr/local/Cellar/mysql55/5.5.30/bin/mysql_install_db --verbose --user=Keiichiro --basedir=/usr/local/Cellar/mysql55/5.5.30 --datadir=/usr/local/var/mysql55 --tmpdir=/tmp
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
mysql -uroot

This formula is keg-only: so it was not symlinked into /usr/local.

Conflicts with mysql, mariadb, percona-server, mysql-cluster, etc.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/mysql55/lib
CPPFLAGS: -I/usr/local/opt/mysql55/include


To have launchd start mysql55 at login:
ln -sfv /usr/local/opt/mysql55/*.plist ~/Library/LaunchAgents
Then to load mysql55 now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql55.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql55/5.5.30: 6405 files, 210M, built in 4.3 minutes

無事インストール出来ました。

MySQLのインストールに限らず、brewコマンドでバージョンを指定してインストールしたい時に、curl: (22) The requested URL returned error: 404
みたいなエラーが出た場合に確認すると解決できるかもです。

ですが、まだ最後に罠がありました。
mysqlコマンドが出てきません。。。
なので、linkをしなければダメだろうと思い


user@pc[~]$ brew unlink mysql

user@pc[~]$ brew link mysql55
Warning: mysql55 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

とまたエラーになります。
なので、支持通り

user@pc[~]$ brew link mysql55 --force
Linking /usr/local/Cellar/mysql55/5.5.30... 133 symlinks created

user@pc[/usr/local]$ mysql.server start
Starting MySQL
SUCCESS!

ということで無事起動確認もできました。