linux-mongodb創建用戶和庫

1.創建admin 用戶

#mongo
#use admin
#db.createUser({user:"admin",pwd:"123456",roles:[{role:"root",db:"admin"}]})

2.配置授權訪問

#vim /etc/mongo.conf
增加:auth=true

3.創建庫/用戶

#mongo
#use admin
#db.auth("admin", "123456")

#use vcollege
#db.createUser({user:"vcollege",pwd:"123456",roles:[{role:"readWrite",db:"vcollege"}]})

4.登錄驗證

mongo --host 127.0.0.1 -u 'vcollege' --authenticationDatabase 'vcollege' -p'123456'mongo --host 127.0.0.1 -u 'vcollege' --authenticationDatabase 'vcollege' -p'123456'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章