mongodb 非 admin 庫 認證登錄失敗 緣由(百度好多都 是渣)db.addUser() 請走開。

首先先曬一下log 日誌錯誤信息mongodb

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" }

着重看一下 這個報錯信息,bash

SCRAM-SHA-1 authentication failed for user1 on finddemo

這是什麼鳥?   工具

mongodb加入了SCRAM-SHA-1校驗方式,須要第三方工具配合進行驗證,下面給出具體解決辦法: spa

首先關閉認證,修改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" } ] }

 

從新鏈接,成功。code

能夠查看一下連接介紹:blog

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

還有國外友人的回答:(愈來愈鄙視百度黨)get

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

相關文章
相關標籤/搜索