mogodb 设置用户名密码认证:

 

#step 1: create account
1. mongo; 
2. use admin; 
3. db.createUser({ user: "root", pwd: "root", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] }); 
4. db.auth("root", "root");

#step2: set authenticate
/etc/mongod.conf 
auth = true  (uncomment it if it's comment)


#step3: restart again
sudo service mongod restart

#step4. check connect :  --host localhost
mongo --port 27017 -u"root" --authenticationDatabase "admin" -p"root"

 

use EDI_Monitor_Platform
db.createUser({ user: "mongodbuser", pwd: "root", roles: [{ role: "dbOwner", db: "EDI_Monitor_Platform" }] })
db.grantRolesToUser("mongodb",[{role:"dbOwner",db:"EDI_Monitor_Platform"}])

 

posted on 2019-05-14 15:12  lshan  阅读(167)  评论(0编辑  收藏  举报