MongoDB数据库安装
下载安装
https://www.mongodb.com/ 打开官网,找到适合自己平台的包,下载解压即可
解压安装后,需要创建一个空的文件夹,用来存放数据,(我在bin的同级下创建了mongo-data文件夹)
启动
1.建议把路径写入环境变量,避免路径过长
2.加入path
$ touch .base_profile
$ vim .base_profile
export MONGO_PATH=/usr/local/mongodb
export PATH=$PATH:$MONGO_PATH/bin
3.重启mongodb服务器,安装以下方法启动
mongod --dbpath /存放数据的地址
4.启动后控制台如下(部分)
2017-10-17T11:04:38.472+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,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-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-10-17T11:04:39.135+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/liuhuanwen/Downloads/mongodb/mongo-data/bd/diagnostic.data'
2017-10-17T11:04:39.135+0800 I NETWORK [thread1] waiting for connections on port 27017
连接mongodb客户端
开启另外一个控制台,输入mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.9
Server has startup warnings:
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten]
2017-10-17T11:04:39.127+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
出现以上内容就成功连接上mongodb了,接下来就去操作你的数据库吧