Starting MongoDB server, it shows error “Permission denied” on one of the database and shutdown the server automatically.
$ mongod
Fri Mar 8 22:54:46 [initandlisten] MongoDB starting : pid=13492
port=27017 dbpath=/data/db/ 64-bit host=Yongs-MacBook-Air.local
//...
Fri Mar 8 22:54:46 [initandlisten] journal dir=/data/db/journal
Fri Mar 8 22:54:46 [initandlisten] recover : no journal files present, no recovery needed
Fri Mar 8 22:54:46 [initandlisten] couldn‘t open /data/db/yourdb.ns errno:13 Permission denied
Fri Mar 8 22:54:46 [initandlisten] error couldn‘t open file /data/db/yourdb.ns terminating
Fri Mar 8 22:54:46 dbexit:
Fri Mar 8 22:54:46 [initandlisten] shutdown: going to close listening sockets...
Fri Mar 8 22:54:46 [initandlisten] shutdown: going to flush diaglog...
Fri Mar 8 22:54:46 [initandlisten] shutdown: going to close sockets...
Fri Mar 8 22:54:46 [initandlisten] shutdown: waiting for fs preallocator...
Fri Mar 8 22:54:46 [initandlisten] shutdown: lock for final commit...
Fri Mar 8 22:54:46 [initandlisten] shutdown: final commit...
Fri Mar 8 22:54:46 [initandlisten] shutdown: closing all files...
Fri Mar 8 22:54:46 [initandlisten] closeAllFiles() finished
Fri Mar 8 22:54:46 [initandlisten] journalCleanup...
Fri Mar 8 22:54:46 [initandlisten] removeJournalFiles
Fri Mar 8 22:54:46 [initandlisten] shutdown: removing fs lock...
Fri Mar 8 22:54:46 dbexit: really exiting now
Solution
The error message is showing that you do not have permission to access yourdb.ns
database. Check the MongoDB data directory /data/db/
, the database yourdb.ns
belongs to the root user.
$ ls -ls /data/db
0 drwxr-xr-x 2 mkyong wheel 68 Mar 8 22:54 journal
131072 -rw------- 1 root wheel 67108864 Mar 7 17:01 yourdb.0
262144 -rw------- 1 root wheel 134217728 Mar 7 16:15 yourdb.1
32768 -rw------- 1 root wheel 16777216 Mar 7 17:01 yourdb.ns
$whoami
mkyong
To fix it, assign permission to the database.
$ sudo chown -R mkyong /data/db
$ ls -ls /data/db
0 drwxr-xr-x 2 mkyong wheel 68 Mar 8 22:54 journal
131072 -rw------- 1 mkyong wheel 67108864 Mar 7 17:01 yourdb.0
262144 -rw------- 1 mkyong wheel 134217728 Mar 7 16:15 yourdb.1
32768 -rw------- 1 mkyong wheel 16777216 Mar 7 17:01 yourdb.ns
转自:
http://www.mkyong.com/mongodb/mongodb-couldnt-open-datadbyourdb-ns-errno13-permission-denied/
时间: 2024-10-08 08:38:04