1. 下载
2. 安装
点击msi文件,选择安装,如下图所示,
next
选择同意,继续next
选择complate,默认安装;custom,自定义安装,可以选择安装路径,安装内容
选择是否安装 mongoDb compass(可视化客户端),这个是在线安装,速度太慢,容易报错,可以暂时不选择,后面独立安装,继续next
选择install,安装,
3. 运行
在安装目录下,创建data、logs 文件夹,并创建 mongo.log,mongo.conf文件,内容如图
其中mongo.conf 文件内容
dbpath=C:\MongoDB\Server\3.6\data #数据库路径
logpath=C:\MongoDB\Server\3.6\logs\mongo.log #日志输出文件路径
logappend=true #错误日志采用追加模式
journal=true #启用日志文件,默认启用
quiet=true #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
port=27017 #端口号 默认为27017
然后进入cmd下,进入 C:\MongoDB\Server\3.6\bin,输入
mongod -config "C:\MongoDB\Server\3.6\mongo.conf"
然后再打开一个cmd命令,
进入
C:\MongoDB\Server\3.6\bin,输入
mongo 127.0.0.1:27017
进入mongo命令,输入 show dbs,
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
mongodb 安装成功
注:
运行时,日志出现警告 Access control is not enabled for the database.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten]
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use admin
switched to db admin
> db.createUser(
... {
... user: "admin", //用户名
... pwd: "passwd", //密码
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //设置权限
... }
... )
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
> commit;
如上,重启数据库,OK
dbpath=C:\MongoDB\Server\3.6\data #数据库路径
logpath=C:\MongoDB\Server\3.6\logs\mongo.log #日志输出文件路径
logappend=true #错误日志采用追加模式
journal=true #启用日志文件,默认启用
quiet=true #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
port=27017 #端口号 默认为27017
mongod -config "C:\MongoDB\Server\3.6\mongo.conf"
mongo 127.0.0.1:27017
进入mongo命令,输入 show dbs,
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
mongodb 安装成功
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten]
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-04-05T21:31:56.080+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
> use admin
switched to db admin
> db.createUser(
... {
... user: "admin", //用户名
... pwd: "passwd", //密码
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] //设置权限
... }
... )
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
> commit;