大家都知道MongoDB是一個(gè)跨平臺(tái)的蓄喇,面向文檔的數(shù)據(jù)庫(kù),提供高性能何暮,高可用性和可擴(kuò)展性方便裤园。那么下面這篇文章就來(lái)給大家介紹了關(guān)于在mac系統(tǒng)下安裝和配置mongodb的方法步驟,需要的朋友可以參考借鑒
mac 系統(tǒng)常用的軟件安裝工具就是homebrew.那么通過(guò)brew怎么安裝mongodb呢?下面小編給大家分享mac下使用brew安裝mongodb的方法教程泻肯,一起看看吧
mac 系統(tǒng)常用的軟件安裝工具就是 homebrew
個(gè)人認(rèn)為通過(guò)brew安裝比較簡(jiǎn)單,下面介紹下如何安裝
安裝 mongodb
- 更新Homebrew的package數(shù)據(jù)庫(kù):
brew update
- 安裝 mongodb
brew install mongodb
成功后出現(xiàn)下面一段描述:
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.4.4.sierra.bottle
Already downloaded: /Users/liangma/Library/Caches/Homebrew/mongodb-3.4.4.sierra.bottle.tar.gz
==> Pouring mongodb-3.4.4.sierra.bottle.tar.gz
==> Using the sandbox
==> Caveats
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
- 查看安裝列表
brew list
mongodb (已經(jīng)存在)
...
- 啟動(dòng)mongodb
啟動(dòng) mongodb之前渊迁,要先新建一個(gè)mongodb默認(rèn)的數(shù)據(jù)寫(xiě)入目錄:
mkdir -p /data/db
mkdir: /data/db: Permission denied (沒(méi)有權(quán)限拒絕訪問(wèn))
// sudo 并輸入密碼,重新新建目錄
sudo mkdir -p /data/db
Password:
給剛才新建的數(shù)據(jù)庫(kù)目錄賦予權(quán)限:
sudo chown `id -u` /data/db
注: ‘id -u‘表明 你當(dāng)前登錄的賬戶名 例如:sudo chown `admin` /data/db
啟動(dòng) mongodb 服務(wù)
mongod --config /usr/local/etc/mongod.conf
成功后會(huì)出現(xiàn)如下:
$ mongod
2017-06-12T16:00:48.036+0800 I CONTROL [initandlisten] MongoDB starting : pid=1837 port=27017 dbpath=/data/db 64-bit host=MacBook-Pro-2.local
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] db version v3.4.0
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] git version: f4240c60f005be757399042dc12f6addbc3170c1
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] allocator: system
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] modules: none
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] build environment:
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] distarch: x86_64
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-06-12T16:00:48.037+0800 I CONTROL [initandlisten] options: {}
2017-06-12T16:00:48.037+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten]
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten]
2017-06-12T16:00:48.665+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-06-12T16:00:48.741+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-06-12T16:00:48.741+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-06-12T16:00:48.755+0800 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-06-12T16:00:48.756+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-06-12T16:00:48.756+0800 I NETWORK [thread1] waiting for connections on port 27017
mongodb 啟動(dòng)成功灶挟,正等待著被連接琉朽。
推薦大家可視化mongodb的可視化工具,下載安裝就可以了 https://robomongo.org/
- 連接mongodb service
mongo
如下:
$ mongo
MongoDB shell version v3.4.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten]
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-06-12T16:00:48.616+0800 I CONTROL [initandlisten]
>
- 使用
查看數(shù)據(jù)庫(kù)
> show dbs
admin 0.000GB
data_person_info 0.000GB
local 0.000GB
test 0.000GB
創(chuàng)建數(shù)據(jù)庫(kù)
> use data_person_info
switched to db data_person_info
查看當(dāng)前數(shù)據(jù)庫(kù)
> db
data_person_info
添加表數(shù)據(jù)(文檔)
> db.data_person_info.insert({'id':'0001','name':'bojue','age':'24'})
WriteResult({ "nInserted" : 1 })
查看表數(shù)據(jù)(文檔)
> db.data_person_info.find()
{ "_id" : ObjectId("59f4c3396564b89187361bfd"), "id" : "0001", "name" : "bojue", "age" : "24" }
- 關(guān)閉mongodb
在操作數(shù)據(jù)庫(kù)的終端輸入
> use admin
后再輸入
> db.shutdownServer()
mongodb 卸載
brew uninstall mongodb
brew list (已經(jīng)不存在 mongodb)
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值稚铣,如果有疑問(wèn)大家可以留言交流箱叁,謝謝大家的支持。