mongoldb在mac下的安裝和配置連接

去官網下載最新的壓縮包:https://www.mongodb.com/download-center#community
壓縮包地址:https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.3.tgz
$tar -xzvf mongodb-osx-ssl-x86_64-3.6.3.tgz
$cp -r mongodb-osx-x86_64-3.6.3/ ./mongodb
$cd mongodb
在新建立的文件夾下建立data文件夾用來記錄數據,log文件夾用來記錄日誌
$mkdir data
$cd data
$mkdir db
$sudo chown -R  wangjinbao db/
$vim mongod.conf
內容如下:
#mongodb config file
dbpath=/Users/wangjinbao/mongodb/data/db/
logpath=/Users/wangjinbao/mongodb/mongod.log
logappend = true
port = 27017
fork = true
auth = true

修改系統環境變量PATH,把/Users/wangjinbao/mongodb/bin目錄加到PATH中
$vim ~/.bash_profile
最後一行加入:
export PATH=/Users/wangjinbao/mongodb/bin:$PATH
刷新生效
$source ~/.bash_profile
查看是否成功
$echo $PATH
$cd bin
$./mongod -f ../mongod.conf

啓動成功後會打印類似於這樣的信息:



打開一個新的終端連接mongodb:

$mongo --host 127.0.0.1:27017

成功連接提示如下:


HomeBrew安裝MongoDB:

Mac HomeBrew安裝mongoldb:
$ brew install mongodb
mongodb: A full installation of Xcode.app 8.3.2 is required to compile this software.
Installing just the Command Line Tools is not sufficient.
Xcode 8.3.2 cannot be installed on macOS 10.11.
You must upgrade your version of macOS.
Error: An unsatisfied requirement failed this build.
報錯的原因:Xcode版本過低
解決方法:
#查看mongoldb的版本
brew search mongodb
#安裝[email protected]
brew install [email protected]
#啓動mongo之前,我們需要創建一個目錄,爲mongo默認的數據寫入目錄
mkdir -p /data/db
添加環境變量:
$export PATH="/usr/local/Cellar/[email protected]/3.4.13/bin:$PATH"
更新:
$source ~/.bash_profile
登錄數據庫:
mongo
創建超級管理員
>use admin
>db.createUser({
user:"wjb",
pwd:"wjb123456",
roles:[
{
role:"userAdminAnyDatabase",
db:"admin"
}
]
})

mongoldb的配置文件地址:
/usr/local/etc/mongod.conf

brew services list#查看啓動的所有服務
brew services start [email protected]#啓動mongodb數據庫

brew services stop [email protected]#停止mongodb數據庫


mongodb 卸載
brew services stop [email protected]
$ brew uninstall mongodb
$ brew list (已經不存在 mongodb)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章