MongoDB4.0.8 在 windows 下的安装配置及Robo 3T连接
安装
-
官网:https://www.mongodb.com/download-center?jmp=nav#community
-
安装:https://blog.csdn.net/qq_22063697/article/details/78069787
-
安装好的目录如下F:\AZtools\MongoDB
-
在安装目录 data 文件夹下创建 新的文件夹 db(我的目录:F:\AZtools\MongoDB\data\db),在 log 文件夹下创建新文件 mongo.log(F:\AZtools\MongoDB\log\mongo.log)
-
打开命令行,cd 到安装目录的 bin 文件夹下,输入命令 mongod –dbpath F:\AZtools\MongoDB\data\db ,出现如下图,即成功
mongod.exe --dbpath "F:\AZtools\MongoDB\data\db"
- 浏览器中输入 http://localhost:27017结果如下:
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
再连接即可: