在windows上安装mongodb(二)

本文详细介绍了如何在Windows上安装MongoDB,包括下载软件、配置文件、设置数据目录、运行服务以及将其作为Windows服务进行管理。同时,还解决了安装过程中可能遇到的权限问题。
摘要由CSDN通过智能技术生成

How to install MongoDB on Windows(二)

In this tutorial, we will show you how to install MongoDB on Windows.

1. MongoDB 2.2.3
2. Windows 7

Note
The MongoDB does not require installation, just download and extracts the zip file, configure the data directory and start it with command “mongod“.

1. Download MongoDB

Download MongoDB from official MongoDB website. Choose Windows 32 bits or 64 bits. Unzip, extracts to your prefer location, for example : d:\mongodb.

2. Review MongoDB folder**

In MongoDB, it contains only 10+ executable files (exe) in the bin folder. This is true, and that are the required files to MongoDB, it’s really hard to believe for a developer like me who come from a relation database background.

Figure : Files under $MongoDB/bin folder
这里写图片描述

Note
It’s recommended to add $MongoDB/bin to Windows environment variable, so that you can access the MongoDB’s commands in command prompt easily.

3. Configuration File

Create a MongoDB config file, it’s just a text file, for example :

d:\mongodb\mongo.config
store data here
dbpath=D:\mongodb\data
all output go here
logpath=D:\mongodb\log\mongo.log
log read and write operations
diaglog=3

这里写图片描述

这里写图片描述

这里写图片描述

mongo.config context:
这里写图片描述

Note
MongoDB need a folder (data directory) to store its data. By default, it will store in “C:\data\db“, create this folder manually. MongoDB won’t create it for you. You can also specify an alternate data directory with –dbpath option.

4. Run MongoDB server

Use mongod.exe –config d:\mongodb\mongo.config to start MongoDB server.

d:\mongodb\bin>mongod –config D:\mongodb\mongo.config
all output going to: D:\mongodb\log\mongo.log

5. Connect to MongoDB

Uses mongo.exe to connect to the started MongoDB server.

d:\mongodb\bin>mongo
MongoDB shell version: 2.2.3
connecting to: test
//mongodb shell

6. MongoDB as Windows Service

Add MongoDB as Windows Service, so that MongoDB will start automatically following each system restart.

Install as Windows Service with –install.

d:\mongodb\bin> mongod –config D:\mongodb\mongo.config –install
A Windows service named “MongoDB” is created.

这里写图片描述

To start MongoDB Service

command: net start MongoDB

这里写图片描述

To stop MongoDB Service

command: net stop MongoDB

To remove MongoDB Service

command: d:\mongodb\bin>mongod –remove

7. FAQs
  1. Install MongoDB as Windows service on Windows 8, but hit “Access is denied.” error message :

C:\Users\mkyong2002>mongod –config D:\mongodb\mongo.config –install
Tue Jul 16 21:05:55.154 diagLogging level=3
Tue Jul 16 21:05:55.155 diagLogging using file D:\mongodb\data/diaglog.51e54533
Tue Jul 16 21:05:55.155 Trying to install Windows service ‘MongoDB’
Tue Jul 16 21:05:55.155 Error connecting to the Service Control Manager: Access
is denied. (5)

To fix it, run the Command Prompt with Administrative Privileges – right click on the command prompt icon, select run as administrator.

From http://www.mkyong.com/mongodb/how-to-install-mongodb-on-windows/

启动MongoDB:net start MongoDB
停止MongoDB:net stop MongoDB
删除MongoDB:sc delete MongoDB

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值