mongorestore[報錯]auth error: sasl c onversation error: unable to authenticate using mechanism

完整報錯:

2020-06-09T17:42:44.532+0800 error connecting to host: could not connect to server: connection() : auth error: sasl c
onversation error: unable to authenticate using mechanism “SCRAM-SHA-1”: (AuthenticationFailed) Authentication failed.

來由:

mongodb中添加了admin表的用戶,即創建了超級管理員(mongodb的安全生產環境的權限設置請查看:
https://blog.csdn.net/Chenftli/article/details/105228130),此時我想去將備份的集合的bson文件數據導入到mongodb指定的數據庫時會報出上面的錯誤。

嘗試

嘗試使用下面的命令執行

.\mongorestore.exe --host 127.0.0.1 --port 27017 --username 用戶名  --password 密碼 -d 恢復集合的數據庫名 "D:\periodical1.bson"

D:\periodical1.bson爲bson數據的路徑,執行過後還是報上面的錯誤

解決:

最後加上下面參數才終於解決問題

--authenticationDatabase admin -u 用戶名 -p 密碼

實例:

./mongorestore.exe --host 127.0.0.1 --port 27017 --authenticationDatabase admi
n -u username -p password -d tests "D:\periodical1.bson"

username爲用戶名,password爲密碼 ,tests爲恢復集合的數據庫名

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章