一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Windows下安装Mongodb的教程

时间:2022-06-30 18:07:01 编辑:袖梨 来源:一聚教程网

1.下载Mongodb

http://www.mongodb.org/downloads

找到自己系统对应的版本,32位或者64位,下载下来

2.将下载的安装包解压到你要安装的目录

例如:D:xamppmongodb,为了方便使用命令行,需要将D:xamppmongodbbin加到系统环境变量的path中。

3.启动Mongodb

使用mongod --dbpath D:xamppmongodbdata命令启动Mongodb

C:Userslxy>mongod --dbpath D:xamppmongodbdata
Wed Apr 02 17:09:54.468 [initandlisten] MongoDB starting : pid=12244 port=27017
dbpath=D:xamppmongodbdata 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:xamppmongodbdat
a" }
Wed Apr 02 17:09:54.519 [initandlisten] journal dir=D:xamppmongodbdatajourna
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:xamppmongodb
datalocal.ns, filling with zeroes...
Wed Apr 02 17:09:54.542 [FileAllocator] creating directory D:xamppmongodbdata
_tmp
Wed Apr 02 17:09:54.627 [FileAllocator] done allocating datafile D:xamppmongod
bdatalocal.ns, size: 16MB,  took 0.083 secs
Wed Apr 02 17:09:54.628 [FileAllocator] allocating new datafile D:xamppmongodb
datalocal.0, filling with zeroes...
Wed Apr 02 17:09:54.838 [FileAllocator] done allocating datafile D:xamppmongod
bdatalocal.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:xamppmongodblogMongoDB.log --logappend --dbpath D:xamppmongodbdata --directoryperdb --serviceName MongoDB --install 安装服务

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
D:xamppmongodbbin>mongod --logpath D:xamppmongodblogMongoDB.log --logappend
--dbpath D:xamppmongodbdata --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:xamppmongodbbinmongod.exe --logpath D:xamppmongodblogMongoDB.log --l
ogappend --dbpath D:xamppmongodbdata --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

热门栏目