首页 > 数据库技术 > 详细

windows下安装MongoDB

时间:2019-05-24 15:07:51      阅读:123      评论:0      收藏:0      [点我收藏+]

  首先自然得先去下载安装包,官网地址:https://www.mongodb.com/download-center#community,默认会提供最新的64位安装包,我看到的是4.0.9。下载后双击该.msi文件 -> 弹框后点Next -> 打√ -> 点Custom -> 点Browse,选择自己想安装的目录 -> 接下来会让你选择是将MongoDB作为windows的服务,默认给你的是windows内置账户(Run service as Network Service user),若勾选下面那个是本地或域用户,需要你自己指定账户和密码。这里我选择不勾选,我想自己来启动MongoDB,所以不勾选上面的Install MongoD as a Service -> 点击Next,这里左下角有个框框默认勾上了,安装图形化界面,我这里也不需要,去掉√ -> 继续Next,最后Install。

  接着准备启动。启动前我们先创建好数据目录,因为刚才我没有勾选配置服务,所以没有创建这两个目录,那就自力更生吧。在E盘创建了E:\MongoDB\data\db和E:\MongoDB\data\log\mongo.log后,我们打开命令行,进入MongoDB的bin目录,执行启动命令mongod:

D:\>cd Dev\MongDB\bin

D:\Dev\MongDB\bin>mongod -dbpath "e:\MongoDB\data\db"  -logpath "e:\MongoDB\data\log\mongo.log"
2019-05-24T14:19:14.893+0800 I CONTROL  [main] log file "e:\MongoDB\data\log\mongo.log" exists; moved to "e:\MongoDB\data\log\mongo.log.2019-05-24T06-19-14".

  它提示说mongo.log已存在,它自己新创建了一个文件了,实际上这两个文件都会记录日志,打开日志看一样:

2019-05-24T14:19:15.310+0800 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols none
2019-05-24T14:19:15.313+0800 I CONTROL  [initandlisten] MongoDB starting : pid=31840 port=27017 dbpath=e:\MongoDB\data\db 64-bit host=wulf00
2019-05-24T14:19:15.313+0800 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] db version v4.0.9
2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765
2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] allocator: tcmalloc
2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] modules: none
2019-05-24T14:19:15.314+0800 I CONTROL  [initandlisten] build environment:
2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     distarch: x86_64
2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2019-05-24T14:19:15.321+0800 I CONTROL  [initandlisten] options: { storage: { dbPath: "e:\MongoDB\data\db" }, systemLog: { destination: "file", path: "e:\MongoDB\data\log\mongo.log" } }
2019-05-24T14:19:15.331+0800 I STORAGE  [initandlisten] Detected data files in e:\MongoDB\data\db created by the wiredTiger storage engine, so setting the active storage engine to wiredTiger.
2019-05-24T14:19:15.331+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3525M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-05-24T14:19:15.525+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:524591][31840:140708351462480], txn-recover: Main recovery loop: starting at 4/5888 to 5/256
2019-05-24T14:19:15.671+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:671179][31840:140708351462480], txn-recover: Recovering log 4 through 5
2019-05-24T14:19:15.770+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:770031][31840:140708351462480], txn-recover: Recovering log 5 through 5
2019-05-24T14:19:15.841+0800 I STORAGE  [initandlisten] WiredTiger message [1558678755:840877][31840:140708351462480], txn-recover: Set global recovery timestamp: 0
2019-05-24T14:19:15.868+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] 
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] 
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] 
2019-05-24T14:19:16.358+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory e:/MongoDB/data/db/diagnostic.data
2019-05-24T14:19:16.360+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

  默认MongoDB监听的端口是27017。接下来我们通过客户端来连接一下,再新开一个命令行窗口 -> 敲命令mongo -> 回车,或者直接双击MongoDB的bin目录下的mongo.exe。我这里直接双击mongo.exe,它会自动连接上我们的mongo服务端,并打印一些信息出来,看到>这个符号就代表它在等待我们的请求了:

MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("cc101713-a114-40a8-815a-5e21f54cb82d") }
MongoDB server version: 4.0.9
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten]
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten]
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
2019-05-24T14:19:15.878+0800 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2019-05-24T14:19:15.879+0800 I CONTROL  [initandlisten]
---
Enable MongoDBs free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> use test
switched to db test
> show collections
> db.wlf.save({"name":"wu linfeng"})
WriteResult({ "nInserted" : 1 })
> show collections
wlf
> db.wlf.findOne()
{ "_id" : ObjectId("5ce78e956abf4e49803d5029"), "name" : "wu linfeng" }
>

  上面先看了下都有哪些库,然后指定了test(没有会自动创建),再看了下有哪些集合(刚创建的库自然是空的),接着用save创建了wlf这个集合并插入了一个属性name。

windows下安装MongoDB

原文:https://www.cnblogs.com/wuxun1997/p/10916809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!