MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

前端 未结 14 1789
轻奢々
轻奢々 2020-12-02 04:37

I created /data/db in root directory and ran ./mongod:

[initandlisten] exception in initAndListen: 20 Attempted to create a lock fi         


        
14条回答
  •  忘掉有多难
    2020-12-02 05:08

    If you do not need to have the database directories in root, you can create data/db in your home directory (mkdir -p ~/data/db).

    Then you can start the MongoDB server with the --dbpath option:

    mongod --dbpath=$(echo ~)/data/db
    

    (This is assuming you're starting it from a terminal. For some strange reason, mongod does not accept ~ as the home directory path, hence the bash echo substitution trickery, you may as well write /home/yourusername/data/db)

    In fact, it does not have to be ~/data/db, it can be anywhere you want and this way you can have multiple database paths and organize everything nicely. May not be the best option for production (depending on what you want to do), but for developing works fine.

提交回复
热议问题