💡解決方案來自: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
暫時無解……