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
提示 “Servicemongodb-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