mongo开启权限配置

1、use admin
2、db.createUser( { user: "admin", pwd: "IJ22glzA*jokw_G24H", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
Successfully added user: {
        "user" : "admin",
        "roles" : [
                {
                        "role" : "userAdminAnyDatabase",
                        "db" : "admin"
                }
        ]
}

3、配置文件中添加
security:
  authorization: enabled

4、重启mongodb服务

5、robo3t中测试没问题保存下
[img=566,0]C:\Users\CTWLPC\AppData\Local\YNote\data\zhengliangsun@163.com\cef2706166124d1cbcb3bc8cffef4239\clipboard.png[/img]

6、shell里登录,需要授权 db.auth("admin", "IJ22glzA*jokw_G24H")
或者mongo --port 27017 -u "admin" -p "IJ22glzA*jokw_G24H" --authenticationDatabase "admin"

7、admin用户只有管理角色和用户的权限,不具有执行权限,需要到其他数据库添加相应权限的用户
use eumnqdb.createUser(  {    user: "eumnq",    pwd: "eumnqpwd",    roles: [ { role: "readWrite", db: "eumnq" }]  })

db.createUser(  {    user: "eumnq1",    pwd: "eumnq1",    roles: [ { role: "read", db: "eumnq" }]  })
发布日期:
分类:mongodb

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注