mongodb 服务器在 SASL 身份验证步骤中返回错误:身份验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38744131/
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
server returned error on SASL authentication step: Authentication failed
提问by Arjun Ajith
The following is my MongoDB connection dial from GoLang. But it's returning a panic "server returned error on SASL authentication step: Authentication failed.". My username, password, hostAddrs and dbName are correct. What am I missing here?
以下是我从 GoLang 的 MongoDB 连接拨号。但它返回一个恐慌“服务器在 SASL 身份验证步骤返回错误:身份验证失败。”。我的用户名、密码、hostAddrs 和 dbName 是正确的。我在这里缺少什么?
dbName: = os.Getenv("ENV_DBNAME")
userName: = os.Getenv("ENV_DBUSER")
password: = os.Getenv("ENV_DBPASS")
dbHost: = os.Getenv("ENV_DBHOST")
mongoDialInfo: = & mgo.DialInfo {
Addrs: [] string {
dbHost
},
Database: dbName,
Username: userName,
Password: password,
Timeout: 60 * time.Second,
}
sess, err: = mgo.DialWithInfo(mongoDialInfo)
if (err != nil) {
panic(err)
}
回答by Anantha
I faced similar error and added --authenticationDatabase
parameter and it worked while we connecting to a remote MongoDB
我遇到了类似的错误并添加了--authenticationDatabase
参数,并且在我们连接到远程 MongoDB 时它起作用了
Use the similar below format in your code :
在您的代码中使用类似的以下格式:
$mongorestore --host databasehost:98761 --username restoreuser
--password restorepwd --authenticationDatabase admin --db targetdb ./path/to/dump/
回答by Geomy George
Often we confused with parameter in the mongoexport command with "Log-In" user. The command expects "Database Username" not Log-in username. This is one possibility to input wrong user name. "Database Username" can be found in "Users" tab for a database
我们经常将 mongoexport 命令中的参数与“登录”用户混淆。该命令需要“数据库用户名”而不是登录用户名。这是输入错误用户名的一种可能性。“数据库用户名”可以在数据库的“用户”选项卡中找到
回答by Michael Shang
I got my answer from this link: https://newbiedba.wordpress.com/2016/11/21/mongodb-3-2-server-returned-error-on-sasl-authentication-step-authentication-failed/
我从这个链接得到了我的答案:https: //newbiedba.wordpress.com/2016/11/21/mongodb-3-2-server-returned-error-on-sasl-authentication-step-authentication-failed/
Except for all answers above, the only unmentioned reason is that my password has a special character '$' in it. I think this is a very common practice to have special characters and this may trip many without this simple tip:
除了上面的所有答案,唯一未提及的原因是我的密码中有一个特殊字符“$”。我认为这是具有特殊字符的一种非常常见的做法,如果没有这个简单的提示,这可能会使许多人绊倒:
When using command line mongo/mongostat/etc.. Single quote your username or password that has special characters!
当使用命令行 mongo/mongostat/etc.. 单引号包含特殊字符的用户名或密码!
回答by CrazyCrow
mgo
returns this error if username
, password
or database
are wrong. Check your credentials twice. There are no other situations when you can see Authentication failed
error message.
mgo
如果或是错误的username
,则返回此错误。检查您的凭据两次。没有其他情况可以看到错误消息。password
database
Authentication failed
回答by Bestbug
The error you report seem the cause of the authentication fail is caused by a nil pointer, you should check the data before using them to create the connection
您报告的错误似乎是认证失败的原因是由 nil 指针引起的,您应该在使用它们创建连接之前检查数据
回答by Seunghun Sunmoon Lee
I had the same error when using with dokku mongo:import . In my case I included dot(period) in my db name
与 dokku mongo:import 一起使用时,我遇到了同样的错误。在我的情况下,我在我的数据库名称中包含了点(句点)
You shouldn't include dot in your mongodb name when 'dokku mongo:create ' I've changed it to seunghunlee instead of seunghunlee.net now this command works
'dokku mongo:create ' 时,您不应在 mongodb 名称中包含点,我已将其更改为 seunghunlee 而不是 seunghunlee.net 现在此命令有效
dokku mongo:import seunghunlee < seunghunlee.net.dump.gz
Hope it helps!
希望能帮助到你!
回答by e18r
I got this error while using a connection string from a Heroku app by means of the --uri
flag. What solved it in my case was adding the database name with -d
:
通过--uri
标志使用来自 Heroku 应用程序的连接字符串时出现此错误。在我的情况下解决它的是添加数据库名称-d
:
mongodb_uri="$(heroku config:get MONGODB_URI -a myapp)"
mongorestore --uri=$mongodb_uri -d heroku_7m41q4xs db/