您的位置:首页 > 数据库 > Mongodb

Mongodb3安装授权

2015-12-10 08:44 381 查看
(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进行远程授权连接啦!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: