Windows上安装MongoDB步骤

事前准备:

1.在mongoDB官网下载.msi文件,我下的是社区版,下载地址:https://www.mongodb.com/download-center#community

2.点击msi文件安装mongoDB,默认安装在C:\Program Files\MongoDB\Server\3.2

3.添加安装路径到环境变量,也就是把C:\Program Files\MongoDB\Server\3.2\bin添加到环境变量里面。关于环境变量:右键点击计算机,选择属性,点击系统高级设置,点击高级里面的环境变量,找到变量名为Path的一行点击编辑,将C:\Program Files\MongoDB\Server\3.2\bin添加到最后,记得跟前面的要用分号隔开

方法一

1.建立mongoDB的数据和log文件夹。比如在D盘建立文件夹mongoDB,在其下分别建立子文件夹data和log。

2.cmd打开命令提示符窗口,输入mongod --dbpath "D:\mongoDB\data" --logpath "D:\mongoDB\log\mongo.log" --install --serviceName "mongoDB",回车

3.net start mongDB,会提示mongoDB服务已经启动成功,默认监听的TCP端口是27017,可以在浏览器地址栏输入localhost:27017,会看到出现:

It looks like you are trying to access MongoDB over HTTP on the native driver port.

4.使用mongo命令进入mongo shell进行数据库的操作

5.使用net stop mongDB关闭服务

方法二

1.建立mongoDB的数据和log文件夹以及配置文件mongo.config。比如在D盘建立文件夹mongoDB,在其下分别建立子文件夹data和log以及配置文件mongo.config。

Windows上安装MongoDB步骤

2.编辑mongo.config:

输入:dbpath=D:\mongoDB\data

logpath=D:\mongoDB\log\mongo.log

storageEngine=mmapv1

......(根据自己的需要添加配置的项目)

注意配置项目之间要换行

3.打开cmd命令窗口,输入:mongod  --config D:\mongoDB\mongo.config

4.打开mongo.log可以看到如下内容即为服务启动成功

2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] MongoDB starting : pid=4924 port=27017 dbpath=D:\mongoDB\data 32-bit host=P0037940-PC
2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] targetMinOS: Windows Vista/Windows Server 2008
2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] db version v3.2.10
2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317
2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] allocator: tcmalloc
2016-11-15T12:29:59.381+0800 I CONTROL [initandlisten] modules: none
2016-11-15T12:29:59.382+0800 I CONTROL [initandlisten] build environment:
2016-11-15T12:29:59.382+0800 I CONTROL [initandlisten] distarch: i386
2016-11-15T12:29:59.382+0800 I CONTROL [initandlisten] target_arch: i386
2016-11-15T12:29:59.382+0800 I CONTROL [initandlisten] options: { config: "D:\mongoDB\mongo.config", storage: { dbPath: "D:\mongoDB\data", engine: "mmapv1" }, systemLog: { destination: "file", path: "D:\mongoDB\log\mongo.log" } }
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten]
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten] ** WARNING: This 32-bit MongoDB binary is deprecated
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten]
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten]
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten] ** See http://dochub.mongodb.org/core/32bit
2016-11-15T12:29:59.943+0800 I CONTROL [initandlisten]
2016-11-15T12:29:59.945+0800 I INDEX [initandlisten] allocating new ns file D:\mongoDB\data\local.ns, filling with zeroes...
2016-11-15T12:30:00.463+0800 I STORAGE [FileAllocator] allocating new datafile D:\mongoDB\data\local.0, filling with zeroes...
2016-11-15T12:30:00.463+0800 I STORAGE [FileAllocator] creating directory D:\mongoDB\data\_tmp
2016-11-15T12:30:00.781+0800 I STORAGE [FileAllocator] done allocating datafile D:\mongoDB\data\local.0, size: 64MB, took 0.314 secs
2016-11-15T12:30:00.789+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-11-15T12:30:00.789+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'D:/mongoDB/data/diagnostic.data'
2016-11-15T12:30:00.792+0800 I NETWORK [initandlisten] waiting for connections on port 27017

5.另开一个cmd窗口,输入mongo,就可以连接到mongodb数据库了

提示:推荐使用第二种方法,第一种在32位Windows下很容易出现问题,别忘了配置引擎

上一篇:Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题


下一篇:How To Get Log, Trace Files In OA Framework Pages And Concurrent Request Programs