Mongodb安装及使用命令

mac上用brew安装:

  1. brew install mongodb
  2. 如果你现在就启动mongo你并不会成功,如下:Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refusedError: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146​ ​​​​​​exception: connect failed
  3. 在启动mongo之前,我们需要创建一个目录,为mongo默认的数据写入目录:默认目录为根目录下的data/db
  4. 切换到  mongodb的bin下
  5. 分别执行:mkdir ~/data 
  6. mongod --dbpath ~/data(这样就是将mongodb的存储目录定位到了~/data下)
  7. 此时出现下图,就说明启动mongodb服务成功了:
  8. 现在就可以开启mongodb进程了。再开启一个新的终端,执行下面的命令:mongo 启动成功
  9. mongodb如何关闭:
  • > use admin
  • > db.shutdownServer()

猜你喜欢

转载自blog.csdn.net/weixin_42446330/article/details/105469739
今日推荐