本文翻译自:Mongod complains that there is no /data/db folder
I am using my new mac for the first time today. 我今天是第一次使用我的新Mac。 I am following the get started guide on the mongodb.org up until the step where one creates the /data/db directory. 我一直遵循mongodb.org上的入门指南,直到创建/ data / db目录的步骤为止。 btw, I used the homebrew route. 顺便说一句,我用自制的路线。
So I open a terminal, and I think I am at what you called the Home Directory, for when I do "ls", I see folders of Desktop Application Movies Music Pictures Documents and Library. 因此,我打开了一个终端,并认为我在您称为主目录的位置,因为当我执行“ ls”操作时,我会看到“桌面应用程序电影”“音乐图片”文档和库的文件夹。
So I did a 所以我做了一个
mkdir -p /data/db
first, it says permission denied. 首先,它说许可被拒绝。 I kept trying different things for half and hour and finally : 我半小时不停地尝试不同的东西,最后:
mkdir -p data/db
worked. 工作了。 and when I "ls", a directory of data and nested in it a db folder do exist. 当我“ ls”时,确实存在一个数据目录并嵌套在其中一个db文件夹。
then I fire up mongod and it complains about not finding data/db 然后我启动mongod,它抱怨找不到数据/数据库
Have I done something wrong? 我做错什么了吗?
Now I have done the 现在我已经完成了
sudo mkdir -p /data/db
and when I do a "ls" I do see the data dir and the db dir. 当我执行“ ls”时,我会看到数据目录和db目录。 inside the db dir though, there is absolutely nothing in it and when I now run mongod 虽然在db目录中,但绝对没有任何内容,当我现在运行mongod时
Sun Oct 30 19:35:19 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Sun Oct 30 19:35:19 dbexit:
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close listening sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to flush diaglog...
Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close sockets...
Sun Oct 30 19:35:19 [initandlisten] shutdown: waiting for fs preallocator...
Sun Oct 30 19:35:19 [initandlisten] shutdown: lock for final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: final commit...
Sun Oct 30 19:35:19 [initandlisten] shutdown: closing all files...
Sun Oct 30 19:35:19 [initandlisten] closeAllFiles() finished
Sun Oct 30 19:35:19 [initandlisten] shutdown: removing fs lock...
Sun Oct 30 19:35:19 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Sun Oct 30 19:35:19 dbexit: really exiting now
EDIT Getting error message for 编辑获取错误消息
sudo chown mongod:mongod /data/db
chown: mongod: Invalid argument
Thanks, everyone! 感谢大家!
#1楼
参考:https://stackoom.com/question/XLqH/Mongod抱怨没有-data-db文件夹
#2楼
After getting the same error as Nik 得到与Nik相同的错误后
chown: id -u: Invalid argument chown:id -u:无效参数
I found out this apparently occurred from using the wrong type of quotation marks (should have been backquotes ) Ubuntu Forums 我发现这显然是从使用了错误类型的引号的发生(应该是反引号 ) Ubuntu论坛
Instead I just used 相反,我只是用
sudo chown $USER /data/db 须藤chown $ USER / data / db
as an alternative and now mongod has the permissions it needs. 作为替代方案,现在mongod拥有所需的权限。
#3楼
I got over this exact same problem by creating the /data/db folders with my window manager. 通过使用窗口管理器创建/ data / db文件夹,我克服了这个完全相同的问题。 I tried doing it though the terminal at first, and in order to create a folder in the root directory, I had to use sudo. 我首先尝试通过终端执行此操作,然后为了在根目录中创建文件夹,我不得不使用sudo。
I just went to the root directory using Finder and created a new folder using 'New Folder'. 我只是使用Finder转到根目录,并使用“新文件夹”创建了一个新文件夹。 Totally worked for me. 完全为我工作。
Note: I'm using OSX. 注意:我正在使用OSX。
#4楼
Just a quick note: 请注意:
If you tried running mongod without changing the permissions first, you'll likely have a mongod.lock file (and some other files) in the /data/db directory. 如果您尝试运行mongod而不先更改权限,则/ data / db目录中可能会有mongod.lock文件(和其他一些文件)。 Even after you change the permissions for the /data/db directory to give access to your $USER, you'll continue to get the "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied" error. 即使您更改了/ data / db目录的访问权限以授予$ USER的访问权限,您仍将继续获得“无法创建/打开锁文件:/data/db/mongod.lock errno:13权限被拒绝”错误。 Run ls -al /data/db and you'll probably see that the permissions for the individual files are still set to root for user, not to your $USER. 运行ls -al / data / db,您可能会发现单个文件的权限仍然设置为root用户,而不是$ USER。 You should remove the mongod.lock file, and the others as well. 您应该删除mongod.lock文件,以及其他文件。 Then when you run mongod again, everything should work, and you can verify that the file permissions match the directory permissions by running ls -al again. 然后,当再次运行mongod时,一切都会正常进行,并且可以通过再次运行ls -al来验证文件权限是否与目录权限匹配。
#5楼
Installing through brew on Mac where YOUR_USER_NAME and staff is the group 在Mac上通过brew进行安装,而YOUR_USER_NAME和staff是该组
sudo mkdir -p /data/db
sudo chmod +x+r+w /data/db/
sudo touch /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db
sudo chmod +x+r+w /data/db/mongod.lock
sudo chown YOUR_USER_NAME:staff /data/db/mongod.lock
#6楼
If you run mongo without arguments it's assume you are running on the production machine so it's use the default locations. 如果您在不带参数的情况下运行mongo,则假定您正在生产机器上运行,因此使用默认位置。
for using your own database (dev or just a different one) : 使用您自己的数据库(dev或其他数据库):
./bin/mongod --dbpath ~/data/db