1.下载Mongodb
http://www.mongodb.org/downloads
找到自己系统对应的版本,32位或者64位,下载下来
2.将下载的安装包解压到你要安装的目录
例如:D:\xampp\mongodb,为了方便使用命令行,需要将D:\xampp\mongodb\bin加到系统环境变量的path中。
3.启动Mongodb
使用mongod --dbpath D:\xampp\mongodb\data命令启动Mongodb
C:\Users\lxy>mongod --dbpath D:\xampp\mongodb\data
Wed Apr 02 17:09:54.468 [initandlisten] MongoDB starting : pid=12244 port=27017
dbpath=D:\xampp\mongodb\data 64-bit host=IdeaBear-PC
Wed Apr 02 17:09:54.469 [initandlisten] db version v2.4.9
Wed Apr 02 17:09:54.470 [initandlisten] git version: 52fe0d21959e32a5bdbecdc6205
7db386e4e029c
Wed Apr 02 17:09:54.471 [initandlisten] build info: windows sys.getwindowsversio
n(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST
_LIB_VERSION=1_49
Wed Apr 02 17:09:54.471 [initandlisten] allocator: system
Wed Apr 02 17:09:54.472 [initandlisten] options: { dbpath: "D:\xampp\mongodb\dat
a" }
Wed Apr 02 17:09:54.519 [initandlisten] journal dir=D:\xampp\mongodb\data\journa
l
Wed Apr 02 17:09:54.520 [initandlisten] recover : no journal files present, no r
ecovery needed
Wed Apr 02 17:09:54.542 [FileAllocator] allocating new datafile D:\xampp\mongodb
\data\local.ns, filling with zeroes...
Wed Apr 02 17:09:54.542 [FileAllocator] creating directory D:\xampp\mongodb\data
\_tmp
Wed Apr 02 17:09:54.627 [FileAllocator] done allocating datafile D:\xampp\mongod
b\data\local.ns, size: 16MB, took 0.083 secs
Wed Apr 02 17:09:54.628 [FileAllocator] allocating new datafile D:\xampp\mongodb
\data\local.0, filling with zeroes...
Wed Apr 02 17:09:54.838 [FileAllocator] done allocating datafile D:\xampp\mongod
b\data\local.0, size: 64MB, took 0.208 secs
Wed Apr 02 17:09:54.840 [initandlisten] command local.$cmd command: { create: "s
tartup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37
297ms
Wed Apr 02 17:09:54.844 [initandlisten] waiting for connections on port 27017
Wed Apr 02 17:09:54.943 [websvr] admin web console waiting for connections on po
rt 28017
最后两行说明了数据库的端口为27017和28017。在浏览器中打开http://localhost:27017,可以看到其相关的一些信息。
4.将Mongodb安装为windows服务
使用命令mongod --logpath D:\xampp\mongodb\log\MongoDB.log --logappend --dbpath D:\xampp\mongodb\data --directoryperdb --serviceName MongoDB --install 安装服务
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
D:\xampp\mongodb\bin>mongod --logpath D:\xampp\mongodb\log\MongoDB.log --logappend
--dbpath D:\xampp\mongodb\data --directoryperdb --serviceName MongoDB --install
Wed Apr 02 17:23:38.146 Trying to install Windows service 'MongoDB'
Wed Apr 02 17:23:38.546 Service 'MongoDB' (Mongo DB) installed with command line
'D:\xampp\mongodb\bin\mongod.exe --logpath D:\xampp\mongodb\log\MongoDB.log --l
ogappend --dbpath D:\xampp\mongodb\data --directoryperdb --service'
Wed Apr 02 17:23:38.546 Service can be started from the command line with 'net s
tart MongoDB'
启动MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB