You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MongoDB启动后自动关闭,提示/data/db目录只读求助

Fixing MongoDB Startup Failure: Read-Only Directory Error

Hey there, let's get your MongoDB up and running! The error message clearly points to a permission issue with the default data directory /data/db—MongoDB can't create the lock file it needs there because the directory is read-only (or doesn't exist at all). Here's how to fix it step by step:

1. Check if the /data/db directory exists

First, let's verify if the directory even exists. Run this command in your terminal:

ls -ld /data/db

If you see a message like No such file or directory, create the directory first with:

sudo mkdir -p /data/db

2. Fix directory permissions

The most common issue here is that your user account doesn't have write access to /data/db. Update the ownership to your user account (replace your_username with your actual system username):

sudo chown -R your_username:your_username /data/db

If you installed MongoDB via a package manager (like apt or yum) and it uses a dedicated mongodb user, use this instead:

sudo chown -R mongodb:mongodb /data/db

3. Alternative: Use a custom data directory (for testing)

If you just want to test MongoDB quickly without modifying system directories, you can specify a custom path with the --dbpath flag. For example, create a local data folder and use it:

mkdir -p ./mongo-data
mongod --dbpath ./mongo-data

Why this happens

MongoDB needs to create a mongod.lock file in its data directory to prevent multiple MongoDB instances from running at the same time. If the directory is read-only, or your user doesn't have permission to write to it, MongoDB can't create this file and shuts down immediately.

内容的提问来源于stack exchange,提问作者AltBrian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:14:06