macOS 升级 Catalina 后,连接 MongoDB 数据库失败

💡解决方案来自:https://www.xuezenghui.com/Catalina_bug/#more

按照 以往方法 连接 MongoDB 数据库时出错:

Data directory /data/db not found ……
原因:

新系统 Catalina 默认不允许往系统分区写文件,SIP(系统完整性保护)状态为开启。

终端中输入 csrutil status 后返回 System Integrity Protection status: enabled. 说明 SIP 处于开启状态。

解决方案:

1. 重启电脑的同时按住 Command + C 进入系统恢复界面。点击上方菜单栏的 实用工具 选择 终端

2. 输入 csrutil disable 关闭 SIP。

3. 重新启动电脑,在 shell 中输入 sudo mount -uw / ,然后就有权限在根目录创建文件夹了。

4. 创建 /data/db 目录 mkdir -p /data/db

如果报错:/data/db: Permission denied.
方法1⃣️:修改当前用户的权限为读与写:
Command + Shift + C,右键点击磁盘,显示简介,最下面修改权限。
方法2⃣️:使用 sudo (没有尝试过,应该🉑️)

创建好 /data/db 目录后,sudo mongod 启动数据库 …… 。


为了系统安全,完了应该重新开启 SIP。

但是如果开启 SIP 后又会报错:

用和上面同样的方法开启SIP:csrutil enable

exception in initAndListen: DBPathInUse: Unable to create/open the lock file: /data/db/mongod.lock (Read-only file system). Ensure the user executing mongod is the owner of the lock file and has the appropriate permissions. Also make sure that another mongod instance is not already running on the /data/db directory, terminating

暂时无解……

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章