您的位置:首页 > 数据库 > Mongodb

Mongodb安装及使用(Mac下Homebrew安装)

2017-01-13 20:27 567 查看
1、更新下Homebrew

brew update

2、安装mongodb,安装完成后的目录:/usr/local/Cellar/mongodb,配置文件目录:/usr/local/etc/mongod.conf

brew install mongodb

3、修改mongod.conf文件,将日志路径和数据库路径指定为自己的路径

systemLog:
destination: file
path: /Users/whc/software/soft/mongodb/log/mongo.log
logAppend: true
storage:
dbPath: /Users/whc/software/soft/mongodb/data
net:
bindIp: 127.0.0.1

4、将mongodb加入环境变量中,vim ~/.bash_profile

#mongodb setting
export MONGODB_HOME=/usr/local/Cellar/mongodb/3.4.1
export PATH=MONGODB_HOME/bin:$PATH

5、通过指定配置文件启动mongo

mongod -f /usr/local/etc/mongod.conf

6、通过客户端连接

whc@BJ1281:~$ mongo localhost:27017
MongoDB shell version v3.4.1
connecting to: mongodb://localhost:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-01-13T20:24:55.543+0800 I CONTROL  [initandlisten]
2017-01-13T20:24:55.543+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-13T20:24:55.543+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-01-13T20:24:55.543+0800 I CONTROL  [initandlisten]

7、关闭mongo服务

> use admin
switched to db admin
> db.shutdownServer()
server should be down...
2017-01-23T19:04:10.666+0800 I NETWORK  [main] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-01-23T19:04:10.667+0800 W NETWORK  [main] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-01-23T19:04:10.667+0800 I NETWORK  [main] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed

8、开始愉快的玩耍吧~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MongoDB