lovecodeblog 2020-01-29
use admin db.createUser({ user:‘admin‘, pwd:‘123‘, roles:[{role:‘root‘,db:‘admin‘}] })
sudo vi /etc/mongod.conf
security: authorization: enabled
sudo service mongod stop sudo service mongod start
mongo -u ‘admin‘ -p ‘123‘ --authenticationDatabase ‘admin‘
use test1 show users
db.createUser({ user:‘t1‘, pwd:‘123‘, roles:[{role:‘readWrite‘,db:‘test1‘}] })
mongo -u t1 -p 123 --authenticationDatabase test1
切换数据库,执行命令查看效果
修改用户:可以修改pwd、roles属性
db.updateUser(‘t1‘,{pwd:‘456‘})