Read-only file system when attempting mkdir /data/db on Mac

后端 未结 16 2072
予麋鹿
予麋鹿 2020-12-07 10:28

I am trying to create a new folder in the main directory

Tried all kinds of examples

sudo mkdir /data/db

sudo mkdir -p /data/db<

相关标签:
16条回答
  • 2020-12-07 10:52

    If you have Mac and updated to Catalina than the root folder is no longer writable.

    I just changed the directory somewhere else.

    Been using this command for now

    mongod --dbpath=/Users/user/data/db
    
    0 讨论(0)
  • 2020-12-07 10:53

    I create a gist with simple steps to install and run mongodb on catalina

    # install homebrew (https://brew.sh/) and run the following commands
    sudo chown -R $(whoami) $(brew --prefix)/*
    brew tap mongodb/brew
    brew install mongodb-community@4.2
    
    ## --- aliases to set in your zshrc file
    
    # open your zshrc file
    open ~/.zshrc
    # copy and paste shorcuts in the end of the file
    alias mongod='brew services run mongodb-community'
    alias mongod-start='brew services start mongodb-community' #will start MongoDB automatically when you login into your Macbook
    alias mongod-status='brew services list'
    alias mongod-stop='brew services stop mongodb-community'
    
    # restart your terminal
    # type mongod in your terminal for run service & mongod-stop for finish it
    # test your mongodb connection with
    mongo
    show dbs
    

    https://gist.github.com/sturmenta/cf19baa91b1d79d8ae2b305fb7e1f799

    0 讨论(0)
  • 2020-12-07 10:55

    This is what worked for me as I was undergoing a Udemy course: 1. Install HomeBrew by typing this into your terminal

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
    1. Move your old /data/db folder (if you want to backup your current dbs) into a non root folder and proceed with the next step

    2. Run in Terminal a) brew uninstall mongodb b) If needed run brew uninstall --force mongodb c) brew tap mongodb/brew d) brew install mongodb-community e) brew services start mongodb/brew/mongodb-community

    3. All you need now is to run mongo in the Terminal and you'll see the mongo shell symbol >.

    Please let me know if this works ;) It took me almost 2 hours to figure it out, based on this article: https://apple.stackexchange.com/questions/362883/mongodb-doesnt-work-after-update-to-macos-catalina-10-15

    Cheers, Radu

    0 讨论(0)
  • 2020-12-07 10:55

    If you are on mac and facing the issue then below command is useful, whoami variable will get the current user

    mongod --dbpath=/Users/$(whoami)/data/db
    
    0 讨论(0)
  • 2020-12-07 10:58

    from the official docs https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

    install homebrew and run the following commands

    sudo chown -R $(whoami) $(brew --prefix)/*

    then

    brew tap mongodb/brew

    then

    brew install mongodb-community@4.2

    and

    brew services start mongodb-community

    or

    mongod --config /usr/local/etc/mongod.conf

    then

    ps aux | grep -v grep | grep mongod

    and

    mongo

    to verify you can run show dbs in the mongo shell

    0 讨论(0)
  • 2020-12-07 11:01

    To make a permanent change of the path of mongod db folder.

    Following these docs they say roughly this. If mongod is started with brew services:

    $ brew services start mongodb-community@4.2
    

    It will use config file at path /usr/local/etc/mongod.conf


    To fix this, edit the config file:

    $ vim /usr/local/etc/mongod.conf
    

    And change the dbPath e.g. to your home directory like this:

    systemLog:
      destination: file
      path: /usr/local/var/log/mongodb/mongo.log
      logAppend: true
    storage:
      dbPath: /Users/<username>/data/db
    net:
      bindIp: 127.0.0.1 
    

    Save the file and restart mongod with brew:

    $ brew services restart mongodb-community@4.2
    
    0 讨论(0)
提交回复
热议问题