Win7下安装MongoDB
1.下载对应的版本:http://www.mongodb.org/downloads
我这里下载的是“mongodb-win32-i386-3.0.5”
2.安装
2.1 解压到任意目录。我这里是C:\mongodb-win32-i386-3.0.5。此时该目录下有bin文件夹。
2.2 mongodb-win32-i386-3.0.5需要db目录(存放数据),log目录(存放日志)的。
手动创建data,db,log文件夹
手动创建data,db,log文件夹
在mongodb目录下建立data文件夹。
在data文件夹建立db文件夹
在data文件夹下建立log文件夹,并在log文件夹下建立mongodb.log文件
2.3 准备工作到位,现在开始安装
打开doc窗口。
进入到mongodb-win32-i386-3.0.5\bin目录
执行::C:\mongodb-win32-i386-3.0.5\bin>mongod -dbpath "C:\mongodb-win32-i386-3.0.5\data\db",出现下面的打印,并且会持续很久!:
[plain]
Tue Mar 05 11:49:37 [initandlisten] waiting for connections on port 27017
注意了!!!!!!!
当看到这行“waiting for connections on port 27017”时,到浏览器中输入地址“localhost:27017”,回车!
浏览器会打印:
You are trying to access MongoDB on the native driver port.
看到如下信息,说明MongoDB已经启动成功了。
[html]
mongod E72C413811423E
List all commands | Replica set status
Commands: buildInfo cursorInfo features hostInfo isMaster listDatabases replSetGetStatus serverStatus top
db version v2.2.3, pdfile version 4.5
git hash: f570771a5d8a3846eb7586eaffcf4c2f4a96bf08
sys info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
uptime: 3932 seconds
overview (only reported if can acquire read lock quickly)
time to get readlock: 0ms
# databases: 1
# Cursors: 0
replication:
master: 0
slave: 0
测试与使用:
新打开一个DOS窗口,win+R, cmd,回车。
进入到C:\mongodb-win32-i386-3.0.5\bin目录,执行命令“C:\mongodb-win32-i386-3.0.5\bin>mongo”,
[html]
C:\mongodb-win32-i386-3.0.5\bin>mongo
2015-07-31T14:19:31.018+0800 I CONTROL Hotfix KB2731284 or later update is not
installed, will zero-out data files
MongoDB shell version: 3.0.5
connecting to: test
Server has startup warnings:
2015-07-31T14:18:29.049+0800 I CONTROL [initandlisten]
2015-07-31T14:18:29.049+0800 I CONTROL [initandlisten] ** NOTE: This is a 32 bi
t MongoDB binary.
2015-07-31T14:18:29.049+0800 I CONTROL [initandlisten] ** 32 bit builds a
re limited to less than 2GB of data (or less with --journal).
2015-07-31T14:18:29.049+0800 I CONTROL [initandlisten] ** Note that journ
aling defaults to off for 32 bit and is currently off.
2015-07-31T14:18:29.049+0800 I CONTROL [initandlisten] ** See http://doch
ub.mongodb.org/core/32bit
2015-07-31T14:18:29.050+0800 I CONTROL [initandlisten]
> db.foo.insert({a:123,b:345})
> db.foo.find()
{ "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
>
test是默认数据库,foo是默认表。简单的插入,查询。
[html]
> db.foo.insert({a:123,b:345})
> db.foo.find()
{ "_id" : ObjectId("51357b2003004382ccd87dcd"), "a" : 123, "b" : 345 }
>
3.为了我们使用方便,我们把mongo注册成服务。这样可以通过控制面板-管理工具-服务来启动和关闭mongo了。
同样的,进入到d:\mongodb2.0\bin目录。
执行命令:
C:\mongodb-win32-i386-3.0.5\bin>mongod -dbpath "C:\mongodb-win32-i386-3.0.5\data\db" --logpath "C:\mongodb-win32-i386-3.0.5\data\log\mongodb.log" --install --serviceName "MongoDB" \\回车
![](https://img-blog.csdn.net/20150731142923112?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)