Mac Brew 服务管理Redis,MySQL

2017/5/4 posted in  Mac

当我在macbook上用brew安装了redis或者mysql服务后,我希望可以方便的查看服务的运行状态,方便的启动停止服务.
然而brew没有这个功能,但是通过安装brewservices就可以管理通过brew安装的相关服务了.这样在开发的过程中就非常的方便了.

安装Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装brewservices

安装这个服务后,我们就可以方便的启动停止用brew安装的相关服务了.比如mysql,redis...

安装

brew tap homebrew/services

使用

  • 查看服务
~ brew services list
Name  Status  User Plist
mysql stopped
redis stopped
  • 启动服务
启动mysql服务
~ brew services start mysql
  ==> Successfully started mysql (label: homebrew.mxcl.mysql)
查看服务状态,redis仍然还是停止的
~ brew services list
  Name  Status  User     Plist
  mysql started hushiwei /Users/hushiwei/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  redis stopped
  • 停止服务
brew services stop mysql

安装MySQL

brew info mysql
brew install mysql

额外配置

# 安装brew服务
brew tap homebrew/services
# 启动mysql服务
brew services start mysql 或者 mysql.server start mysql.server stop
# 查看mysql的版本
mysql -V

# 配置mysql的root密码
mysqladmin -u root password 'yourpassword'

mysql -uroot -p

安装redis

brew install redis
  • redis 配置文件的位置 /usr/local/etc/redis.conf
  • 使用配置文件启动redis server /usr/local/etc/redis.conf
  • 卸载redis和它的文件 brew uninstall redis rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
  • 测试redis server是否启动 /usr/local/bin/redis-cli ping 或者 redis-cli ping ## brew service管理redis `` # 启动redis服务 hushiwei@hsw ~ brew services start redis ==> Successfully startedredis` (label: homebrew.mxcl.redis)

停止redis服务

hushiwei@hsw ~ brew services stop redis
Stopping redis... (might take a while)
==> Successfully stopped redis (label: homebrew.mxcl.redis)

启动redis客户端

/usr/local/bin/redis-cli 或者 redis-cli
```