mongodb开启身份验证
前言
此处记录一下mongodb开启身份验证的步骤
具体步骤
- 安装mongodb
mac下直接使用homebrew安装即可:brew install mongodb,windows则下载对应的安装包
- 创建用户
# 超级管理员
use admin
db.createUser({
user: "root",
pwd: "pwd",
customData: {description: "管理员用户"},
roles: ["root"],
})
# 业务数据库用户
use tradition
db.createUser({
user: "tradition",
pwd: "pwd",
roles:[
{role:"readWrite", db:"tradition"},
{role: "dbAdmin", db:"tradition"},
]
})
- 开启验证
mac需要修改 /usr/local/etc/mongod.conf,windows修改安装目录下的mongod.cfg,添加以下两行配置
security:
authorization: enabled