mongodb 开启用户密码访问

连接mongo

mongo --port 27017

创建admin账号:

use admin

db.createUser(
  {
    user: "admin",
    pwd: "passwd",
    roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"]
  }
)

admin登录

mongo --port 27017  --authenticationDatabase "admin" -u "admin" -p "SPb365U44s"

创建库用户

use file
db.createUser(
  {
    user: "file_owner",
    pwd:  "passwd",
    roles: [ { role: "dbOwner", db: "file" }]
  }
)

登录测试

mongo --port 27017  --authenticationDatabase "file" -u "file_owner" -p "passwd"
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页