linux 下mongo 密码忘记以及创建数据库密码
1.通过ps -ef|grep mongod找到mongodb的配置文件mongod.conf
将security:authorization: enabled注释
2.重启mongod
systemctl restart mongod
3.登录mongo
use admin
db.system.users.find()
db.system.users.remove({})
4.创建admin用户
db.createUser({user:'admin',pwd:'XXXXXXX',roles:[{"role":"userAdminAnyDatabase","db":"admin"}]})
5.验证 db.auth('admin','XXXXXX')
6.创建MERCHANT
use MERCHANT
7.创建MERCHANT用户aihaimi
db.createUser({user:'aihaimi',pwd:'XXXXXX',roles:[{"role":"readWrite","db":"MERCHANT"}]})
8.认证
db.auth('aihaimi','111111')
9.插入数据(保存创建的所有:不然会数据库创建不成功)
db.MERCHANT.insert({"test":"test"})
10.完成