Mongodb3安装授权

(1)

mongodb 官网下载解压包
mongodb-win32-x86_64-3.0.7.zip
解压释放在d盘,目录为mongodb,接下来手动创建data文件夹和log文件夹分别用于存放数据和日志。

(2)安装mongodb服务(不带auth参数安装)
cmd进入shell命令窗口

C:\Users\Administrator>d:

D:\>cd D:\mongodb\bin

mongod --logpath D:\mongodb\log\mongodb.log --logappend --dbpath D:\mongodb\data --serviceName MongoDB --install

紧接着执行服务启动命令:

net start MongoDB

(3)

cmd进入shell命令窗口

C:\Users\Administrator>d:

D:\>cd D:\mongodb\bin

D:\mongodb\bin>mongo

MongoDB shell version: 3.0.7
connecting to: test

> use admin
switched to db admin
> db.createUser({user: "admin",pwd: "123456",roles: ["root"]})
Successfully added user: { "user" : "admin", "roles" : [ "root" ] }

> use admin
switched to db admin
> var schema = db.system.version.findOne({"_id" : "authSchema"})
> schema.currentVersion=3
> db.system.version.save(schema)

> use admin
switched to db admin
> db.createUser({user:"sa",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})

> use mtc
switched to db mtc
> db.createUser({user:"root",pwd:"123456",roles:[{role:"readWrite",db:"mtc"}]})

> db.auth("root","rtqw998358")

> exit

(4)执行服务停止命令
net stop MongoDB
紧接着执行服务安装命令(带auth参数):
mongod --logpath D:\mongodb\log\mongodb.log --logappend --dbpath D:\mongodb\data --serviceName MongoDB --auth --install
然后执行服务启动命令:
net start MongoDB

(5)然后就能通过的客户端工具mongodb vue进行远程授权连接啦!

posted @ 2015-12-10 08:44  火腿骑士  阅读(193)  评论(0编辑  收藏  举报