mongodb 无法使用 --db 创建备份 mongodump。认证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31993168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't create backup mongodump with --db. Authentication failed
提问by Vladislav Orillo
When I create backup of all databases in MongoDB (version 3):
当我在 MongoDB(版本 3)中创建所有数据库的备份时:
mongodump --username bacUser --password 12345
It's OK. But when I try to create backup of a selected db:
没关系。但是当我尝试创建选定数据库的备份时:
mongodump --username bacUser --password 12345 --db test
It gives me this error:
它给了我这个错误:
Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.
失败:连接到数据库服务器时出错:服务器在 SASL 身份验证步骤中返回错误:身份验证失败。
回答by Vladislav Orillo
work with this:
使用这个:
--authenticationDatabase admin
mongodump and mongorestore commands need the name of database where mongodb user's credentials are stored. (thanks @Zubair Alam)
mongodump 和 mongorestore 命令需要存储 mongodb 用户凭据的数据库名称。(感谢@Zubair Alam)
回答by Milos Matic
This should work.
这应该有效。
mongodump -h SERVER_NAME:PORT -d DATABASE_NAME -u DATABASE_USER -p PASSWORD
Also this error can popup if username or password are wrong.
如果用户名或密码错误,也会弹出此错误。
回答by Gyanendro Loitongbam
mongodump --collection coll_name --db DBname -u UName -p ***
--authenticationDatabase <admin/privileged> --host ip
--port portNo --out foldName
回答by Shirish Singh
If you still get same error with --authenticationDatabase admin , than probably your username and password are incorrect. Try adding a user db.createUser() , with appropriate role ( i gave write permission as well)
如果您仍然遇到与 --authenticationDatabase admin 相同的错误,那么您的用户名和密码可能不正确。尝试添加一个用户 db.createUser() ,具有适当的角色(我也给了写权限)
than run below command : (ignore -h if you are running on local)
比在命令下运行:(如果您在本地运行,请忽略 -h)
mongodump -h <ip>:<port_number> -d db_name -u newUser -p newPassword -o /home/mongodump/
Hope this helps...
希望这可以帮助...
回答by Ganesh
mongodump --host <host-ip> --port 27017 --db <database> --authenticationDatabase admin --username <username> --password <password> --out ./Documents/
After all the trail, I found above working command to dump from mongdb.
经过所有的跟踪,我发现上面的工作命令可以从 mongdb 转储。
回答by user3784566
for dump and restore
用于转储和恢复
mongodump --db nameDatabase --username userName --password password --authenticationDatabase admin --out mongodb\
mongorestore --db nameDatabase --username userName --password password --authenticationDatabase admin <path backup> --drop
回答by user2996950
The following steps worked for me on MongoDB 3.2:
以下步骤在 MongoDB 3.2 上对我有用:
- Check of course if your admin username and pw are correct. You can do this with the mongo shell:
- 当然,请检查您的管理员用户名和密码是否正确。您可以使用 mongo shell 执行此操作:
mongo
蒙戈
use admin db.auth("admin", "yourpassword")
使用 admin db.auth("admin", "yourpassword")
If this returns 1, the password is correct.
如果返回 1,则密码正确。
Then add the role "backup" to your admin (or make sure this role is already added). db.grantRolesToUser("admin", [{ role: "backup", db: "admin" }])
Finally, the mongodump command. It did not work for me when I tried to pass the password as an argument. Instead do this:
然后将角色“备份”添加到您的管理员(或确保已添加此角色)。db.grantRolesToUser("admin", [{ role: "backup", db: "admin" }])
最后是 mongodump 命令。当我尝试将密码作为参数传递时,它对我不起作用。而是这样做:
mongodump --username admin --authenticationDatabase admin --db yourmongodatabase
mongodump --username admin --authenticationDatabase admin --db yourmongodatabase
Then add your password when it promts for it.
然后在提示时添加您的密码。
This works for me...
这对我有用...
回答by adeel
Use signle Quotation around password. if you are using any special character in your password. That will solve your issue. Use following command.
在密码周围使用单引号。如果您在密码中使用任何特殊字符。那将解决您的问题。使用以下命令。
mongodump -d database_name -u userName -p 'password' --out directory_name
mongodump -d 数据库名称 -u 用户名 -p '密码' --out directory_name
回答by user2722165
In my case, mongodump
was not correctly processing the password. The solution was to escape the password literal.
就我而言,mongodump
没有正确处理密码。解决方案是转义密码文字。
This did not work:
这不起作用:
mongodump -p my$password -o <output directory>
mongodump -p my$password -o <output directory>
This did work:
这确实有效:
mongodump -p 'my$password' -o <output directory>
mongodump -p 'my$password' -o <output directory>
回答by Gert van den Berg
If you use the --uri
option, you need to add authSource=admin
as a parameter to your connection string (assuming your user is on the admin database)
如果使用该--uri
选项,则需要将authSource=admin
作为参数添加到连接字符串中(假设您的用户在 admin 数据库中)
mongodump --uri="mongodb://user:pass@host1:27017,host2:27017,host3:27017/?replicaSet=rs0"
Becomes:
变成:
mongodump --db=test --uri="mongodb://user:pass@host1:27017,host2:27017,host3:27017/?replicaSet=rs0&authSoource=admin"