2023-04-06 安裝mongodb和清空mongodb數(shù)據(jù)庫(kù)

1、清空mongodb數(shù)據(jù)庫(kù)

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服務(wù):brew services stop mongodb-community@4.4

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

重啟mongodb服務(wù):brew services start mongodb-community@4.4
這樣就清空了mongodb數(shù)據(jù)庫(kù)所有數(shù)據(jù)。

2、安裝mongodb數(shù)據(jù)庫(kù)

  • 在安裝社區(qū)版前要先執(zhí)行: brew tap mongodb/brew 這個(gè)過(guò)程有點(diǎn)久,我裝過(guò)可能需要30分鐘左右。
  • 安裝最新社區(qū)版:brew reinstall mongodb-community
  • 啟動(dòng) mongodb-community 服務(wù):brew services start mongodb-community
    提示 “Service mongodb-community already started”,說(shuō)明服務(wù)啟動(dòng)成功

mongodb-community 命令區(qū)別 mongodb

  • 啟動(dòng)服務(wù):brew services start mongodb-community
  • 重啟服務(wù): brew services restart mongodb-community
  • 停止服務(wù):brew services stop mongodb-community
  • 安裝某個(gè)版本:brew install mongodb-community@x.x.x
  • 手動(dòng)啟動(dòng)服務(wù):mongod --config /usr/local/etc/mongod.conf

文件路徑:

  • 配置文件:/usr/local/etc/mongod.conf
  • 日志目錄路徑:/usr/local/var/log/mongodb
  • 數(shù)據(jù)目錄路徑:/usr/local/var/mongodb

這樣 MongoDB 服務(wù)就安裝和啟動(dòng)好了。

將 MongoDB 下載到本地,mongodb-osx-ssl-x86_64-4.0.13.tgz 我下載的是這個(gè)版本,解壓后,新建目錄,將解壓后的文件存放在里面。

我的目錄為:/Volumes/code/localhost/node/mongodb/bin

  • 創(chuàng)建存儲(chǔ)數(shù)據(jù)庫(kù)文件 data
       在任意盤符根目錄下創(chuàng)建一個(gè) data 目錄,用來(lái)存放數(shù)據(jù)庫(kù)文件。 mongoDB 會(huì)自動(dòng)把自己安裝位置的盤符根目錄下的 data 文件夾作為自己的數(shù)據(jù)存儲(chǔ)目錄,這里也可以直接在安裝位置所在盤符創(chuàng)建,我是在 bin 目錄下創(chuàng)建的 data 目錄。

新開(kāi)一個(gè) shell,指定 db 路徑:

進(jìn)入 /Volumes/code/localhost/node/mongodb/bin 目錄 ,輸入 mongod,會(huì)看到 :

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

db version v4.2.1

git version: edf6d45851c0b9ee15548f0f847df141764a317e

。。。

說(shuō)明 db 啟動(dòng)成功了!!

如果 data 目錄在其它位置,需要指定 data 目錄路徑,輸入 mongod --dbpath 路徑

默認(rèn)情況下,db 啟動(dòng)成功后,本地會(huì)有三個(gè)表 admin / config / local

轉(zhuǎn):https://www.cnblogs.com/baiyygynui/p/11865647.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容