Mac使用brew安装MongoDB

之前一直使用以下命令安装MongoDB,但是一直安装不上

brew install mongodb

后来看了官网,安装方法如下

brew tap mongodb/brew    //这步不知道需不需要
brew install [email protected]

使用brew安装好的MongoDB,默认会在如下位置创建相关文件

  • the configuration file (/usr/local/etc/mongod.conf)
  • the log directory path (/usr/local/var/log/mongodb)
  • the data directory path (/usr/local/var/mongodb)

启动关闭MongoDB有两种方法
方法一:使用brew

// 启动
brew services start [email protected]
// 关闭
brew services stop [email protected]

方法二:使用环境变量
在用户根目录下使用如下命令

sudo vim .bash_profile

添加如下变量

export PATH=/usr/local/Cellar/mongodb-community/4.2.0/bin:${PATH}}

启动MongoDB服务

sudo mongod

启动MongoDB的shell

mongo

猜你喜欢

转载自www.cnblogs.com/georgeleoo/p/11479409.html