homebrewでインストールしたmysqlを自動起動する
1. homebrewでmysqlがインストールされたディレクトリを探す
2. そのディレクトリ以下に、「homebrew.mxcl.mysql.plist」というファイルがあるので、コピーする。
cp /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
3. コピーしたファイルのUserNameを書き換える
13 <key>UserName</key> 14 <string>mike</string> # mikeを自分の名前に書き換える
※自分の名前はwhoamiコマンドで確認
4. launchctl
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
※tmuxとかを使ってるとうまくいかないので注意! → launchctl loadが動かない件 - idesaku blog
参考
- osx - autostart mysql on boot from terminal - Stack Overflow
- Can't autostart MySQL with LaunchAgent as _mysql · Issue #11710 · mxcl/homebrew
追記
brew upgrade mysqlして最新版のmysql入れたら、最後にこんなメッセージがでてきた。
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
こっちのほうが簡単。