首页 > 代码库 > mongo启动

mongo启动

1. ps -aux | grep mongo 确定mongo的启动的命令以及端口号

         502 34786 ttys000    2:53.29 /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf

2.pkill mongod 杀掉mongod

3.修改 /usr/local/etc/mongod.conf 的文件 然后重新启动

4.重新启动  /usr/local/opt/mongodb/bin/mongod --config /usr/local/etc/mongod.conf

5.mongod添加权限控制

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

use xxxx
db.addUser(‘xxxx‘,‘xxxx‘)

use xxxx
db.addUser(‘xxxx‘,‘xxxx‘)

mongo客户端验证登录:

mongo -u "xxxx" -p "xxxx" --authenticationDatabase "admin"

权限验证:

use xxxx
db.auth(‘xxxx‘,‘xxxx‘)

 

mongo启动