MongoDB4.0.8 在 windows 下的安装配置及Robo 3T连接

MongoDB4.0.8 在 windows 下的安装配置及Robo 3T连接

安装

mongod.exe --dbpath "F:\AZtools\MongoDB\data\db"

在这里插入图片描述

It looks like you are trying to access MongoDB over HTTP on the native driver port.

测试使用

  • 保持MongoDB开启,使用安装目录\bin\下的mongo.exe可以启动MongoDB的操作终端:
F:\AZtools\MongoDB\bin>mongo.exe
MongoDB shell version v4.0.8
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("00074250-44bb-4961-bdfe-2e1f2af79329") }
MongoDB server version: 4.0.8
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-04-08T07:12:30.618-0700 I CONTROL  [initandlisten]
2019-04-08T07:12:30.618-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-04-08T07:12:30.618-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-04-08T07:12:30.618-0700 I CONTROL  [initandlisten]
---
Enable MongoDB's 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()
---

> db
test
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

检查本地服务在这里插入图片描述

可以用如下命令关闭服务:

net stop MongoDB

出现拒绝访问错误:
在这里插入图片描述
应用管理员身份运行cmd:
在这里插入图片描述

可以用如下命令开启服务(管理员身份运行cmd):

net start MongoDB

在这里插入图片描述
移除服务
进入到mongodb安装目录的bin目录下开启cmd(管理员身份运行cmd):

 sc delete "MongoDB"

配置为 windows 服务

  • 以管理员身份打开命令行,cd 到安装目录的 bin 文件夹下,执行以下命令:
mongod –dbpath F:\AZtools\MongoDB\data\db –logpath F:\AZtools\MongoDB\log\mongo.log –logappend –serviceName MongoDB –auth –install 

其中数据库路径为F:\AZtools\MongoDB\data\db,日志路径为F:\AZtools\MongoDB\log\mongo.log,服务名为MongoDB。

  • 可以在任务管理器的服务列表中查看(此时未开启)
    在这里插入图片描述
  • 运行 cmd (管理员身份运行cmd)直接执行:net start MongoDB ,提示服务启动成功。 net stop MongoDB 用来关闭服务
    出现以下错误:
    在这里插入图片描述
    参考:https://blog.csdn.net/jian_xi/article/details/73359790
    成功:
    在这里插入图片描述

可视化工具Robo 3T

  • 创建连接
    在这里插入图片描述
    出现错误:
Cannot connect to the MongoDB at localhost:27017.

Error:
Failed to execute "listdatabases" command.

在这里插入图片描述
原因:
在创建服务的时候,开启了用户验证,mongod –dbpath F:\AZtools\MongoDB\data\db –logpath F:\AZtools\MongoDB\log\mongo.log –logappend –serviceName MongoDB –auth –install 就不能直接连接了,要创建用户和密码了,具体参考:https://www.cnblogs.com/shuibingyue/p/7101361.html
我是直接删除了之前的MongoDB服务:
sc delete MongoDB
然后重新安装服务(不含用户密码的):
管理员运行cmd,进入bin目录下,运行以下命令,然后开启服务:

mongod -dbpath F:\AZtools\MongoDB\data\db -logpath F:\AZtools\MongoDB\log\mongo.log -logappend -serviceName MongoDB  -install

在这里插入图片描述
再连接即可:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41104835/article/details/89139148