码迷,mamicode.com
首页 > 数据库 > 详细

mongodb 非 admin 库 认证登陆失败 原因(百度好多都 是渣)db.addUser() 请走开。

时间:2016-07-14 02:48:04      阅读:568      评论:0      收藏:0      [点我收藏+]

标签:

首先先晒一下log 日志错误信息

2016-07-13T22:19:43.667+0800 I ACCESS   [conn4]  authenticate db: finddemo { aut
henticate: 1, nonce: "xxx", user: "user1", key: "xxx" }
2016-07-13T22:19:43.668+0800 I ACCESS   [conn4] Failed to authenticate user1@fin
ddemo with mechanism MONGODB-CR: AuthenticationFailed: UserNotFound: Could not f
ind user user1@finddemo
2016-07-13T22:20:12.555+0800 I ACCESS   [conn2] SCRAM-SHA-1 authentication faile
d for user1 on finddemo from client 127.0.0.1 ; UserNotFound: Could not find use
r user1@finddemo
2016-07-13T22:20:17.127+0800 I NETWORK  [initandlisten] connection accepted from
 127.0.0.1:56103 #5 (4 connections now open)
2016-07-13T22:20:17.127+0800 I ACCESS   [conn5]  authenticate db: admin { authen
ticate: 1, nonce: "xxx", user: "root", key: "xxx" }
2016-07-13T22:20:17.146+0800 I NETWORK  [initandlisten] connection accepted from
 127.0.0.1:56104 #6 (5 connections now open)
2016-07-13T22:20:17.146+0800 I ACCESS   [conn6]  authenticate db: admin { authen
ticate: 1, nonce: "xxx", user: "root", key: "xxx" }

着重看一下 这个报错信息,

SCRAM-SHA-1 authentication failed for user1 on finddemo

这是什么鸟?   

mongodb加入了SCRAM-SHA-1校验方式,需要第三方工具配合进行验证,下面给出具体解决办法: 

首先关闭认证,修改system.version文档里面的authSchema版本为3,初始安装时候应该是5,命令行如下: 

> use admin 
switched to db admin 
>  var schema = db.system.version.findOne({"_id" : "authSchema"}) 
> schema.currentVersion = 3 
3 
> db.system.version.save(schema) 
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })  

 

 

下面是获取到的用户的相关信息

{ "_id" : "admin.root", "user" : "root", "db" : "admin", "credentials" : { "MONGODB-CR" : "97a156792bd180dc82cec9a56d838991" }, "roles" : [ { "role" : "__system", "db" : "admin" } ] }
{ "_id" : "finddemo.finddemo", "user" : "finddemo", "db" : "finddemo", "credentials" : { "MONGODB-CR" : "4b8dce39de95d553473c1998f43aa165" }, "roles" : [ { "role" : "dbOwner", "db" : "finddemo" } ] }

 

重新连接,成功。

可以查看一下链接介绍:

https://docs.mongodb.com/master/release-notes/3.0-scram/

还有国外友人的回答:(越来越鄙视百度党)

http://stackoverflow.com/questions/29006887/mongodb-cr-authentication-failed

  

mongodb 非 admin 库 认证登陆失败 原因(百度好多都 是渣)db.addUser() 请走开。

标签:

原文地址:http://www.cnblogs.com/timelesszhuang/p/5668589.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!