将通过Homebrew安装的MySQL和MongoDB配置为自动启动

想做的事情 zuò de shì

我想在Mac登录时,通过Homebrew安装并自动启动MySQL和MongoDB。

环境

    • OS X 10.9.2

 

    Homebrew 0.9.5

做过的事情 (Done things)

MySQL和MongoDB的安装

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

如果在链接时出现以下错误,请先进行一次解除链接,然后重新进行链接。

$ 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

当启动失败时

如果由于操作系统的异常关闭等原因导致锁定文件残留并导致启动失败时的处理方法。

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
rm /usr/local/var/mongodb/mongod.lock
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
广告
将在 10 秒后关闭
bannerAds