- 添加超级管理员
use admin db.createUser({user: "doracms",pwd: "doracms",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
- 添加相关数据库用户
db.createUser({user: "doracms",pwd: "doracms",roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]})
- mongodb.conf
/usr/local/mongodb4/bin/etc/mongodb.conf
查找mongodb.conf存放位置
find / -name mongodb.conf
- 启动mongo
cd /usr/local/mongodb4/bin ./mongod --config ./mongodb.conf
- mongodb.conf配置
dbpath=/usr/local/mongodb/data/ #数据存放路径 logpath=/usr/local/mongodb/log/mongodb.log #日志存放路径 auth=true fork=true
- 停止mongo
mongo use admin db.auth('root', 'root') // 在admin认证过后才能继续操作 db.shutdownServer();
- 修改mongodb 数据库密码
db.changeUserPassword('admin','test');
- 查看全局user
```
use admin switched to db admin db.auth(‘admin’,’123456’) 1 db.system.users.find().pretty()
- 查看当前数据库下的用户
use admin switched to db admin show users ```