windows下安装与配置mongodb

1.下载mongodb
下载地址为
http://www.mongodb.org/downloads ,根据OS选择安装的版本.
我这里下载的是mongodb-win32-i386-2.0.8.zip
 
2.解压缩mongodb-win32-i386-2.0.8.zip
解压缩该zip包,我这里解压缩到E:\soft\mongodb-win32-i386-2.0.8,同时在该目录下创建db和log两个文件夹,这样的话该目录有如下三个文件夹.
E:\soft\mongodb-win32-i386-2.0.8\bin
E:\soft\mongodb-win32-i386-2.0.8\db
E:\soft\mongodb-win32-i386-2.0.8\log

在log文件夹下创建日志文件MongoDB.log,完全目录为E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log
 
3.在PATH变量中加入E:\soft\mongodb-win32-i386-2.0.8\bin,这样就可以直接调用bin目录下的exe文件.
 
4.执行如下命令
mongod -dbpath "E:\soft\mongodb-win32-i386-2.0.8\db"
执行此命令即将mongodb的数据库文件创建到E:\soft\mongodb-win32-i386-2.0.8\db目录
Sun Dec 02 10:09:18 [clientcursormon] mem (MB) res:0 virt:44 mapped:
 
5.运行mongo.exe
C:\Documents and Settings\xueliang.huang>mongo
MongoDB shell version: 2.0.8
connecting to: test
> help
        db.help()                    help on db methods
        db.mycoll.help()             help on collection methods
        rs.help()                    help on replica set methods
        help admin                   administrative help
        help connect                 connecting to a db help
        help keys                    key shortcuts
        help misc                    misc things to know
        help mr                      mapreduce
        show dbs                     show database names
        show collections             show collections in current database
        show users                   show users in current database
        show profile                 show most recent system.profile entries with time >= 1ms
        show logs                    show the accessible logger names
        show log [name]              prints out the last segment of log in memory, 'global' is default
        use <db_name>                set current database
        db.foo.find()                list objects in collection foo
        db.foo.find( { a : 1 } )     list objects in foo where a == 1
        it                           result of the last line evaluated; use to further iterate
        DBQuery.shellBatchSize = x   set default number of items to display on shell
        exit                         quit the mongo shell
当mongod.exe被关闭时,mongo.exe 就无法连接到数据库了,因此每次想使用mongodb数据库都要开启mongod.exe程序,所以比较麻烦,接下来我们将接下来我们将
MongoDB安装为windows服务吧
 
6.MongoDB安装为windows服务
创建服务
mongod --dbpath "E:\soft\mongodb-win32-i386-2.0.8\db" --logpath "E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log" --install --serviceName "mongodb"
net start mongodb(开启服务)
net stop mongodb(关闭服务)
删除服务
mongod --dbpath "E:\soft\mongodb-win32-i386-2.0.8\db" --logpath "E:\soft\mongodb-win32-i386-2.0.8\log\MongoDB.log" --remove --serviceName "MongoDB"
mongod --dbpath "c:\mymongodb" --logpath "c:\mymongodb\logs.txt" --install --serviceName "MongoDB"
要是出现如下错误的话需要将db目录下的mongod.lock删除后再启动
>mongo

>couldn't connect to server 127.0.0.1 shell/mongo.js:84

---------------------------/******分割线******--------------------------------------

创建windows服务,就是以最好记住的命令net start mongodb 来代替启动并指定db文件路径的复杂命令;使用mongod时,只需两步:

1-net start mongodb(服务名)

2-mongo /前提是保证已经将mongo.exe的bin路径加入到windows 的path环境变量中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值