MongoDB 的安装、启动与连接
- 一、MongoDB Community Server
- 1. 安装
- (1) 下载
- (2) 安装
- 1) 解压
- 2) 配置环境变量
- 3) 配置数据库存放目录
- a. 创建
- b. 赋权
- 2. 启动
- 验证
- 二、MongoDB Compass
- 安装
- 三、连接
一、MongoDB Community Server
1. 安装
(1) 下载
官网下载安装
(2) 安装
1) 解压
2) 配置环境变量
- 新建 ~/.bash_profile
cd
touch .bash_profile
- 打开该文件
open .bash_profile
- 将 MongoDB 的二进制命令文件目录(安装目录/bin)添加到 PATH 路径中
export PATH=<MongoDB Server 的解压目录>/bin:$PATH
- 执行 source 命令使其生效
source .bash_profile
3) 配置数据库存放目录
a. 创建
cd <MongoDB Server 的解压目录>
mkdir -p data/db
b. 赋权
给当前用户对该目录赋予读写的权限
sudo chown data/db
2. 启动
mongod --dbpath </data/db 的路径>
终端返回... waiting for connections ...
说明启动成功
验证
浏览器访问
二、MongoDB Compass
安装
官网下载并安装
三、连接
打开 Compass,使用默认的连接本地 DB 配置,即可连接成功