Mongodb连接认证errmsg: "auth failed"解决方法

连接方式:mongo --host xxxx --port 27017 -u xxx -p xxx
报错:

connected to: 192.168.xx.xx:27017
assertion: 18 { ok: 0.0, errmsg: "auth failed", code: 18, codeName: "AuthenticationFailed" }

MongoDB shell version: 2.6.12
connecting to: 192.168.xx.xx:27017/test
2020-08-24T11:24:13.216+0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18, codeName: "AuthenticationFailed" } at src/mongo/shell/db.js:1292

系统:Centos7
MongoDB client:mongo2.6.12(yum默认安装)
MongoDB server:mongo3.6

解决方法:
yum remove mongodb*
出处:https://www.cnblogs.com/liucx/
方法一:
Mongdb阿里云源地址:https://developer.aliyun.com/mirror/mongodb?spm=a2c6h.13651102.0.0.3e221b11WKzAH6
vi /etc/yum.repos.d/mongodb-org.repo
添加内容如下:(配置偶数版本,奇数版不适合生产使用)
[mongodb-org]
name = MongoDB Repository
baseurl = https://mirrors.aliyun.com/mongodb/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck = 1
enabled = 1
gpgkey = https:// www.mongodb.org/static/pgp/server-3.6.asc

yum makecache

安装mongodb3.6版本

yum -y install mongodb-org-mongos-3.6.3 mongodb-org-tools-3.6.3

mongodb-org-tools:这个里面有mongodump、mongorestore、mongoexport和mongoimport工具

方法二:
或者去http://mirrors.163.com/mongodb/yum/el7-3.6/RPMS/
下载需要的rpm包,直接安装rpm -ivh *.rpm

posted @ 2020-08-24 11:56  Mr'liu  阅读(4776)  评论(0编辑  收藏  举报