官方教程(for windows):http://www.mongodb.org/display/DOCS/Quickstart+Windows
对 MongoDb 文档数据库感兴趣,要安装认识下。
到官方下载 win 版 http://www.mongodb.org/display/DOCS/Downloads 目前最新稳定版是 1.2.4。解压到 f:/sofr/mongodb-win32-i386-1.2.4。
1.启动 mongod 服务端
F:\soft\mongodb>bin\mongod.exe –dbpath=f:/mongodb
Mon Mar 08 11:13:17 Mongo DB : starting : pid = 0 port = 27017 dbpath = f:/mongodb master = 0 slave
= 0 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations for more
Mon Mar 08 11:13:18 db version v1.2.4, pdfile version 4.5
Mon Mar 08 11:13:18 git version: 5cf582d3d96b882c400c33e7670b811ccd47f477
Mon Mar 08 11:13:18 sys info: windows (5, 1, 2600, 2, ‘Service Pack 3’) BOOST_LIB_VERSION=1_35
Mon Mar 08 11:13:18 waiting for connections on port 27017
–dbpath 指定数据库的目录,默认是 /data/db,win 没有 /data/db 目录,所以直接双击 mongod 是启动不了。默认端口是 27017
下面来将MongoDB加入到Windows服务(http://www.mongodb.org/display/DOCS/Windows+Service):
F:/soft/mongodb/bin>mongod.exe --dbpath=F:/mongodb/data --logpath=F:/mongodb/logs/logs.txt
--logappend --bind_ip 127.0.0.1 --directoryperdb --install
参数:
–dbpath 这个指定数据库的存放路径
–logpath 指定日志文件
–logappend 追加的方式
–bind_ip 绑定IP地址
–directoryperdb 每个数据库单独存放在一个文件夹内
–install 安装到Windows服务,默认服务名为 MongoDB
You may use the following options with –install, –reinstall and –remove: in the examples, {arg} is any text. Use quotes around the text if it includes spaces.
–serviceName {arg} |
Specify the service name (used with “net start/stop”, and usually does not include spaces) |
–serviceDisplayName {arg} |
Specify the service’s display name |
–serviceDescription {arg} |
Specify the service’s description |
–serviceUser {arg} |
Specify login account for running the service (account must have the “Log on as a service” right) |
–servicePassword {arg} |
Specify password for login account |
成功之后可以看到类似下面的信息:
all output going to: F:/mongodb/logs/logs.txt
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via ‘net start “MongoDB”‘.
注意:路径路径要使用绝对路径,不能使用相对路径.否则会出错!
启用MongoDB服务
f:/soft/mongodb/bin>net start MongoDB
Continue reading →