Mongo下载安装

一、使用Brew 安装

1
2
3
brew tap mongodb/brew
// 下载 后面指定版本
brew install mongodb
截屏2021-08-13 17.41.49

执行 echo ’export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"’ » ~/.zshrc

二、启动

1
brew services start mongodb

如果想要使用 mongod 来启动并制定配置文件位置

.bash_profile添加配置

1
2
# MongoDB Aliases
alias mongod="mongod --config /usr/local/etc/mongod.conf --fork"

启动问题

1
2
如果启动时提示:Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
在配置文件中指定了新的data位置。

三、配置文件

1
2
3
4
5
6
7
8
systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /usr/local/var/mongodb
net:
  bindIp: 127.0.0.1

四、创建员工

4.0 启动mongo

4.1 已非授权模式登陆

1
mongo

4.2 切换到admin数据库

1
use admin

4.3 创建用户

1
2
3
4
5
db.createUser({
 user: "huochai",
 pwd: "Asdf1234",
 roles:[ "dbOwner" ]
 })

4.4 认证

1
db.auth("huochai","Asdf1234")

4.5 登陆客户端

url mongodb://huochai:Asdf1234@127.0.01:27017

数据库之间的账号是独立的,需要在新建的数据库中在重新创建用户

mongodb://appraisal:appraisal@101.200.156.46:27018/appraisal?authSource=appraisal

Built with Hugo
主题 StackJimmy 设计

本站访客数 人次   总访问量   本文阅读量