mongodb4.0配置用户名密码认证登录

 

 

 

 

 

> use admin
switched to db admin
> db.createUser({user:"root",pwd:"root",roles:[{role:"readWrite",db:"admin"},{role:"userAdminAnyDatabase",db:"admin"}]})
Successfully added user: {
    "user" : "root",
    "roles" : [
        {
            "role" : "readWrite",
            "db" : "admin"
        },
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}
> 

 配置文件添加

security:
  authorization: enabled

 

[root@liruilong ~]# vim /etc/mongod.conf 
[root@liruilong ~]# systemctl restart mongod.service
[root@liruilong ~]# mongo
MongoDB shell version v4.0.20
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("4e5f7400-7fb5-4adf-8530-97906b118048") }
MongoDB server version: 4.0.20

 

posted @ 2020-08-29 17:44  山河已无恙  阅读(761)  评论(0编辑  收藏  举报