0.简述:在非auth下创建账户,然后重启
1.以不需要用户名密码的方式启动mongodb
2.运行客户端mongo,输入以下指令
show dbs; use admin; db.createRole({role:'sysadmin',roles:[], privileges:[{resource:{anyResource:true},actions:['anyAction']}]}) db.createUser({user: "root", pwd: "abcd1234", roles: [ { role: "sysadmin", db: "admin" } ] } ); db.system.users.find(); |
3.重启mongod服务器,命令行增加--auth或者配置文件增加:auth=true
4.运行客户端mongo,输入以下指令测试
use admin db.auth("root","abcd1234") show dbs |
5.更改密码
db.updateUser("root", {pwd: "abcde12345"} ); 或者(推荐下面的) db.changeUserPassword('root', 'abcde12345'); |
6.测试
use test1 db.users.insert({"name":"bigbear","password":"12345678"}) db.users.find() |
7.修正数据库错误
mongod --repair |