大家好,又见面了,我是全栈君。
一.Windows 平台安装 MongoDB
1.MongoDB 下载
MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制包下载地址:https://www.mongodb.com/download-center/community
2.一步一步默认安装就好,我的安装目录自定义
3.配置环境变量,使在任意位置都可以执行bin下的exe程序
我们设置了环境变量(path)的话,在命令提示符的任何地方都可以使用mongoDB的命令了。
4.设置数据存储目录
D:\softwore\mongodb3\bin>mongod.exe –dbpath D:\softwore\mongodb3\data\db
D:\softwore\mongodb3\bin>mongod.exe --dbpath D:\softwore\mongodb3\data\db
2021-09-08T15:42:06.102+0800 I CONTROL [initandlisten] MongoDB starting : pid=26020 port=27017 dbpath=D:\softwore\mongodb3\data\db 64-bit host=LEJU-1UT79B6G6B
2021-09-08T15:42:06.108+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2021-09-08T15:42:06.112+0800 I CONTROL [initandlisten] db version v3.0.15
2021-09-08T15:42:06.112+0800 I CONTROL [initandlisten] git version: b8ff507269c382bc100fc52f75f48d54cd42ec3b
2021-09-08T15:42:06.114+0800 I CONTROL [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2021-09-08T15:42:06.115+0800 I CONTROL [initandlisten] allocator: tcmalloc
2021-09-08T15:42:06.116+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "D:\softwore\mongodb3\data\db" } }
2021-09-08T15:42:06.132+0800 I JOURNAL [initandlisten] journal dir=D:\softwore\mongodb3\data\db\journal
2021-09-08T15:42:06.134+0800 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2021-09-08T15:42:06.183+0800 I JOURNAL [durability] Durability thread started
2021-09-08T15:42:06.186+0800 I JOURNAL [journal writer] Journal writer thread started
2021-09-08T15:42:06.238+0800 I INDEX [initandlisten] allocating new ns file D:\softwore\mongodb3\data\db\local.ns, filling with zeroes...
2021-09-08T15:42:06.390+0800 I STORAGE [FileAllocator] allocating new datafile D:\softwore\mongodb3\data\db\local.0, filling with zeroes...
2021-09-08T15:42:06.392+0800 I STORAGE [FileAllocator] creating directory D:\softwore\mongodb3\data\db\_tmp
2021-09-08T15:42:06.413+0800 I STORAGE [FileAllocator] done allocating datafile D:\softwore\mongodb3\data\db\local.0, size: 64MB, took 0.013 secs
2021-09-08T15:42:06.451+0800 I NETWORK [initandlisten] waiting for connections on port 27017
5.链接mongodb
我们可以在命令窗口中运行 mongo.exe 命令即可连接上 MongoDB,执行如下命令:
6.测试
最后:浏览器访问
7.win10设置Mongodb启动为Windows服务自启动
遇到问题:
1.net start MongoDB 服务名无效错误解决
1.将data目录下的所有文件都删除; 2.以管理员模式打开cmd,cd到mongodb bin目录下,运行: mongod –config “D:\Mongo\mongo.conf” –install –serviceName “MongoDB” 再运行: net start MongoDB
2.解决连接mongoDB出现问题:MongoDB : Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
cmd 命令行以管理员身份运行命令 :
mongod --config "D:\softwore\mongodb3\mongod.cfg"
参考:https://www.runoob.com/mongodb/mongodb-window-install.html
https://www.cnblogs.com/duhuo/p/4552132.html
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/111445.html原文链接:https://javaforall.cn