Mac 下安装mongoDB


安装mogodb

之前说过homebrew的安装,在homebrew中只用使用下面的命令来安装

brew install mongodb

启动mongo

  1. 在终端执行命令

    mongod
  2. 打开新终端,执行以下命令

    mongo

存在的一些问题

  1. 安装后提示:exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating

    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] MongoDB starting : pid=2372 port=27017 dbpath=/data/db 64-bit host=chus-MacBook-Pro.local
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] db version v3.6.3
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] allocator: system
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] modules: none
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] build environment:
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten]     distarch: x86_64
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten]     target_arch: x86_64
    2018-08-17T00:00:37.936+0800 I CONTROL  [initandlisten] options: {}
    2018-08-17T00:00:37.940+0800 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
    2018-08-17T00:00:37.940+0800 I CONTROL  [initandlisten] now exiting
    2018-08-17T00:00:37.940+0800 I CONTROL  [initandlisten] shutting down with code:100
    

    原因:在/data/db 下的Data目录找不到
    解决方法:要使用root权限来创建Data文件

    sudo mkdir -p /data/db
  2. 当创建了目录之后,运行mogod依然报错,exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating

    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] db version v3.6.3
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o  27 Mar 2018
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] allocator: system
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] modules: none
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] build environment:
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten]     distarch: x86_64
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten]     target_arch: x86_64
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] options: {}
    2018-08-17T00:05:12.196+0800 I STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] now exiting
    2018-08-17T00:05:12.196+0800 I CONTROL  [initandlisten] shutting down with code:100

    原因:没有权限
    解决办法:给db权限

    sudo chown `id -u` /data/db

运行结果

mongod这里写图片描述

mongo这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值