本文将介绍在Windows10上面安装 mongodb-3.4.15 绿色版本。个人并不是很喜欢采用exe/msi等方式去安装mongodb,除非没得选了。
(1)将下载的压缩包 mongodb-3.4.15.rar 解压到指定的目录。加压后的目录结构如下:
(2)在mongodb 目录下面创建一个data目录。如下:
(3)通过 binmongod.exe 命令启动 mongodb。如下:
mongod.exe --dbpath D:mongodb-3.4.15data
启动日志,如下:
2020-02-14T20:59:21.725+0800 I CONTROL [initandlisten] MongoDB starting : pid=15688 port=27017 dbpath=D:servermongodb-3.4.15\data 64-bit host=ZQCBUIB1T9KD4J6 2020-02-14T20:59:21.727+0800 I CONTROL [initandlisten] targetMinOS: Windows Vista/Windows Server 2008 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] db version v3.4.15-52-g874aa31cae 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] git version: 874aa31cae91abbfdd2cbe10810e9e8d7dd98f6d 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] allocator: tcmalloc 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] modules: none 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] build environment: 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] distarch: x86_64 2020-02-14T20:59:21.728+0800 I CONTROL [initandlisten] target_arch: x86_64 2020-02-14T20:59:21.729+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "D:servermongodb-3.4.15\data" } } 2020-02-14T20:59:21.731+0800 I - [initandlisten] Detected data files in D:servermongodb-3.4.15\data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2020-02-14T20:59:21.732+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7550M,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),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress), 2020-02-14T20:59:22.094+0800 I STORAGE [initandlisten] WiredTiger message [1581685162:93425][15688:140716502113872], txn-recover: Main recovery loop: starting at 17/23552 2020-02-14T20:59:22.307+0800 I STORAGE [initandlisten] WiredTiger message [1581685162:306305][15688:140716502113872], txn-recover: Recovering log 17 through 18 2020-02-14T20:59:22.426+0800 I STORAGE [initandlisten] WiredTiger message [1581685162:426233][15688:140716502113872], txn-recover: Recovering log 18 through 18 2020-02-14T20:59:22.600+0800 I CONTROL [initandlisten] 2020-02-14T20:59:22.600+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2020-02-14T20:59:22.600+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2020-02-14T20:59:22.600+0800 I CONTROL [initandlisten] 2020-02-14T20:59:24.069+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'D:/server/mongodb-3.4.15//data/diagnostic.data' 2020-02-14T20:59:24.071+0800 I NETWORK [thread1] waiting for connections on port 27017
看见上面最后 27027 了吗?这就是 mongodb 的端口。恭喜你,启动成功了!!
注意:上面启动的 mongodb 不需要用户名和密码都可以连接。如果你需要账号和密码验证,需要使用 --auth 选项开启权限验证。
执行下面命令,开启mongodb的权限认证。命令如下:
mongod.exe --dbpath D:mongodb-3.4.15data --auth
成功启动 mongodb 以后,使用 mongo.exe 连接 mongodb。过程如下:
D:mongodb-3.4.15in> mongo.exe MongoDB shell version v3.4.15-52-g874aa31cae connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.15-52-g874aa31cae > show dbs; 2020-02-14T21:15:57.823+0800 E QUERY [thread1] Error: listDatabases failed:{ "ok" : 0, "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }", "code" : 13, "codeName" : "Unauthorized" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1 shellHelper.show@src/mongo/shell/utils.js:788:19 shellHelper@src/mongo/shell/utils.js:678:15 @(shellhelp2):1:1 >
使用 show dbs 查看数据库列表,但是报错了,因为没有权限(你没有登录)。