一、下载安装
https://www.mongodb.com/download-center#community
或者选用官网推荐的
Instructions for installing with Homebrew
接下来我们使用 curl 命令来下载安装:
# 进入 /usr/local 本地地址随意
cd /usr/local
# 下载 根据你所需要的版本
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.2.tgz
# 解压
sudo tar -zxvf mongodb-osx-x86_64-3.4.2.tgz
# 重命名为 mongodb 目录
sudo mv mongodb-osx-x86_64-3.4.2 mongodb
安装完成后,我们可以把 MongoDB 的二进制命令文件目录(安装目录/bin)添加到 PATH 路径中:
export PATH=/usr/local/mongodb/bin:$PATH
brew只要一步
$sudo brew install mongodb
==> Pouring mongodb-3.6.5.high_sierra.bottle.tar.gz
==> Caveats
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb/3.6.5: 19 files, 297.9MB
二、创建数据库db文件夹
默认是/data/db 你也可以到mongo.conf里去自定义,vi /usr/local/etc/mongod.conf
$sudo mkdir -p /data/db
三、启动MongoDB
需要先启动服务,不然会出现错误
[thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
[thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed
$brew services start mongodb
$mongod
四、运行MongoDB
$mongo
出现
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.5
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
五、在使用时候引入pymongo
import pymongo
网友评论