Mongodb账户权限配置
第一步 创建超级管理用户
这是整个数据库(所有数据库的超级管理员,可以给每个数据库设置管理员)
use admin db.createUser({ user:'admin', pwd:'123456', roles:[{role:'root',db:'admin'}] // root表示超级管理员 })
第二步 修改Mongodb数据库配置文件
找到Mongodb的安装目录到bin目录,里面有个文件mongod.cfg,修改security:authorization: enabled,开启用户权限
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: C:Program FilesMongoDBServer4.0data journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: C:Program FilesMongoDBServer4.0logmongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1 #processManagement: #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
注意前面是两个空格
# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: C:Program FilesMongoDBServer4.0data journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: C:Program FilesMongoDBServer4.0logmongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1 #processManagement: security: authorization: enabled #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
第三步 重启mongodb服务
第四步 用超级管理员账户连接数据库
mongo admin -u 用户名 -p 密码
第五步 给eggcms数据库创建一个用户,只能访问eggcms不能访问其他数据库