在CentOS上管理MongoDB用户,您需要遵循以下步骤:
登录到您的CentOS服务器。
启动MongoDB服务(如果尚未启动):
sudo systemctl start mongod
mongo
命令连接到MongoDB shell:mongo
admin
数据库:use admin
db.createUser({
user: "adminUser",
pwd: "your_password",
roles: ["root"]
})
exit
mongo -u adminUser -p your_password --authenticationDatabase admin
myDatabase
的数据库中创建一个名为myUser
的用户,请执行以下命令:use myDatabase
db.createUser({
user: "myUser",
pwd: "your_password",
roles: [
{
role: "readWrite",
db: "myDatabase"
}
]
})
db.updateUser("myUser", {
pwd: "new_password",
roles: [
{
role: "readWrite",
db: "myDatabase"
}
]
})
db.dropUser("myUser")
mongo -u adminUser -p your_password --authenticationDatabase admin
现在您已经在CentOS上成功管理了MongoDB用户。请确保为每个数据库创建具有适当角色的用户,以便根据需要限制访问权限。