mongodb 开启用户密码访问

it2026-03-15  4

连接mongo

mongo --port 27017

创建admin账号:

use admin db.createUser( { user: "admin", pwd: "passwd", roles: [{ role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"] } )

admin登录

mongo --port 27017 --authenticationDatabase "admin" -u "admin" -p "SPb365U44s"

创建库用户

use file db.createUser( { user: "file_owner", pwd: "passwd", roles: [ { role: "dbOwner", db: "file" }] } )

登录测试

mongo --port 27017 --authenticationDatabase "file" -u "file_owner" -p "passwd"
最新回复(0)