2023-04-06 安装mongodb和清空mongodb数据

2023-04-05  本文已影响0人  我是小胡胡123

1、清空mongodb数据库

brew services list

~/Library/LaunchAgents/homebrew.mxcl.mongodb-community@4.4.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebrew.mxcl.mongodb-community@4.4</string>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/homebrew/opt/mongodb-community@4.4/bin/mongod</string>
    <string>--config</string>
    <string>/opt/homebrew/etc/mongod.conf</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>WorkingDirectory</key>
  <string>/opt/homebrew</string>
  <key>StandardErrorPath</key>
  <string>/opt/homebrew/var/log/mongodb/output.log</string>
  <key>StandardOutPath</key>
  <string>/opt/homebrew/var/log/mongodb/output.log</string>
  <key>HardResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>64000</integer>
  </dict>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>64000</integer>
  </dict>
</dict>
</plist>

/opt/homebrew/etc/mongod.conf

systemLog:
  destination: file
  path: /opt/homebrew/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /opt/homebrew/var/mongodb
net:
  bindIp: 127.0.0.1, ::1
  ipv6: true

停止mongodb服务:brew services stop mongodb-community@4.4

删除/opt/homebrew/var/mongodb/*
删除/opt/homebrew/var/log/mongodb/*

重启mongodb服务:brew services start mongodb-community@4.4
这样就清空了mongodb数据库所有数据。

2、安装mongodb数据库

mongodb-community 命令区别 mongodb

文件路径:

这样 MongoDB 服务就安装和启动好了。

将 MongoDB 下载到本地,mongodb-osx-ssl-x86_64-4.0.13.tgz 我下载的是这个版本,解压后,新建目录,将解压后的文件存放在里面。

我的目录为:/Volumes/code/localhost/node/mongodb/bin

新开一个 shell,指定 db 路径:

进入 /Volumes/code/localhost/node/mongodb/bin 目录 ,输入 mongod,会看到 :

MongoDB starting : pid=942 port=27017 dbpath=/data/db 64-bit

db version v4.2.1

git version: edf6d45851c0b9ee15548f0f847df141764a317e

。。。

说明 db 启动成功了!!

如果 data 目录在其它位置,需要指定 data 目录路径,输入 mongod --dbpath 路径

默认情况下,db 启动成功后,本地会有三个表 admin / config / local

转:https://www.cnblogs.com/baiyygynui/p/11865647.html

上一篇 下一篇

猜你喜欢

热点阅读