Windows下MongoDB安装配置
1:下载MongoDB最新版
2:安装路路径
D:\MongoDB\Server\3.4
3:创建数据库路径(data目录)、日志路径(logs目录)和日志文件(mongo.log文件)
4:创建配置文件mongo.conf,文件内容如下
dbpath=D:\MongoDB\Server\3.4\data #数据库路径
logpath=D:\MongoDB\Server\3.4\logs\mongo.log #日志输出文件路径
logappend=true #错误日志采用追加模式
journal=true #启用日志文件,默认启用
quiet=true #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
port=27017 #端口号 默认为27017
5:启动
D:\MongoDB\Server\3.4\bin>mongod --config "D:\MongoDB\Server\3.4\mongo.conf"
查看是否启动:http://127.0.0.1:27017/
6:进行用户创建以及启动认证用户信息方式
(1)非授权模式启动 D:\MongoDB\Server\3.4\bin>mongod --config "D:\MongoDB\Server\3.4\mongo.conf" (2)创建用户 > use admin switched to db admin > db.createUser({user: "test",pwd: "test",roles: [ { role: "root", db: "admin" } ]}) Successfully added user: { "user" : "test", "roles" : [ { "role" : "root", "db" : "admin" } ] } > db.shutdownServer() (3)授权模式启动 D:\MongoDB\Server\3.4\bin>mongod --config "D:\MongoDB\Server\3.4\mongo.conf" --auth (4)授权认证登录 D:\MongoDB\Server\3.4\bin>mongo MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.2 > use admin switched to db admin > db.auth("test","test") 1 (5)新建数据库及用户并授权 > use yshy switched to db yshy > db.createUser({user:"yshy",pwd:"yshy",roles:[{role:"readWrite",db:"yshy"}]}) Successfully added user: { "user" : "yshy", "roles" : [ { "role" : "readWrite", "db" : "yshy" } ] } >