LoginSignup
71
71

More than 5 years have passed since last update.

HomebrewでインストールしたMySQL,MongoDBを自動起動させる

Last updated at Posted at 2014-04-05

やりたいこと

HomebrewでMySQL,MongoDBをインストールて、Macログイン時に自動起動させたい。

環境

  • OS X 10.9.2
  • Homebrew 0.9.5

やったこと

MySQL,MongoDBのインストール

brew install mysql
brew link mysql
brew install mongodb
brew link mongodb

link時に以下のようなエラーが出た場合は、一回unlinkしてからリンクし直す。

$ brew link mysql
Warning: Already linked: /usr/local/Cellar/mysql/5.6.16
To relink: brew unlink mysql && brew link mysql

自動起動の設定

ln -fs /usr/local/opt/mysql/homebrew.mxcl.mysql.plist ~/Library/LaunchAgents/
ln -fs /usr/local/opt/mongodb/homebrew.mxcl.mongodb.plist ~/Library/LaunchAgents/

すぐに起動する場合

次回、再起動時に自動起動されるが、設定後すぐに起動する場合は以下実行する。

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

起動しているか確認

$ ps ax | grep mysql
34910   ??  S      0:00.02 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1
35003   ??  S      0:00.65 /usr/local/Cellar/mysql/5.6.16/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.6.16 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.16/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/maru.local.err --pid-file=/usr/local/var/mysql/maru.local.pid
35153 s001  S+     0:00.00 grep mysql

$ ps ax | grep mongo
35142   ??  S      0:00.15 /usr/local/opt/mongodb/mongod run --config /usr/local/etc/mongod.conf
35162 s001  S+     0:00.00 grep mongo

起動に失敗した時

OSの不正終了等で lock ファイルが残っていて起動に失敗した場合の対応

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
rm /usr/local/var/mongodb/mongod.lock
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
71
71
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
71
71