mongodb(一)-入门
参考:
http://www.yiibai.com/mongodb/
http://blog.csdn.net/yuwenruli/article/details/8529192
一、是什么
mongodb是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便。
下面列出RDBMS术语与mongodb的关系:
Database 数据库 | Database |
Table 表 | Collection |
Tuple/Row 行 | Document |
column 列 | Field |
Table Join 联表 | Embedded Documents |
Primary Key 主键 | Primary Key (Default key _id provided by mongodb itself) |
Mysqld/Oracle | mongod |
mysql/sqlplus | mongo |
不适用场景:
1、高度事务性系统
2、复杂的跨表级查询
二、安装
1. 下载相应版本的mongodb:mongodb-linux-x86_64-3.0.4
2. 放到任意目录,比如:/home/mongodb-linux-x86_64-3.0.4
3. 新建数据文件夹和日志文件:
[root@www mongodb-linux-x86_64-3.0.4]# mkdir data [root@www mongodb-linux-x86_64-3.0.4]# touch logs三、启动
[root@www home]# cd mongodb-linux-x86_64-3.0.4/bin/ [root@www bin]# ./mongod --dbpath=/home/mongodb-linux-x86_64-3.0.4/data/ --logpath=/home/mongodb-linux-x86_64-3.0.4/logs --logappend --port=27017 --fork about to fork child process, waiting until server is ready for connections. forked process: 4528 child process started successfully, parent exiting参数解释:
--dbpath 数据库路径(数据文件)
--logpath 日志文件路径
--logappend 日志文件末尾增加
--port 启用端口号
> use joan switched to db joan > db.dropDatabase() { "ok" : 1 }
--fork 启用子进程运行
用配置文件来启动:每次启动mongodb时,都要配置如此多参数,是不是有点太麻烦了?我们可以用配置文件来代替。
配置文件内容:
dbpath = /home/mongodb-linux-x86_64-3.0.4/data port = 27017 fork = ture logappend = true logpath = /home/mongodb-linux-x86_64-3.0.4/logs
Last login: Thu Jul 30 06:16:34 2015 [root@www ~]# cd /home/mongodb-linux-x86_64-3.0.4/ [root@www mongodb-linux-x86_64-3.0.4]# mkdir data/mongodb_27017 [root@www mongodb-linux-x86_64-3.0.4]# cd data/mongodb_27017/ [root@www mongodb_27017]# vi mongodb_27017.cnf [root@www mongodb_27017]# cd .. [root@www data]# cd .. [root@www mongodb-linux-x86_64-3.0.4]# cd bin/ [root@www bin]# ./mongod -f /home/mongodb-linux-x86_64-3.0.4/data/mongodb_27017/mongodb_27017.cnf about to fork child process, waiting until server is ready for connections. forked process: 2381 child process started successfully, parent exiting
查看配置文件:
> use admin switched to db admin > db.runCommand({getCmdLineOpts:1}) { "argv" : [ "./mongod", "-f", "/home/mongodb-linux-x86_64-3.0.4/data/mongodb_27017/mongodb_27017.cnf" ], "parsed" : { "config" : "/home/mongodb-linux-x86_64-3.0.4/data/mongodb_27017/mongodb_27017.cnf", "net" : { "port" : 27017 }, "processManagement" : { "fork" : true }, "storage" : { "dbPath" : "/home/mongodb-linux-x86_64-3.0.4/data" }, "systemLog" : { "destination" : "file", "logAppend" : true, "path" : "/home/mongodb-linux-x86_64-3.0.4/logs" } }, "ok" : 1 }
四、客户端连接
[root@www bin]# ./mongo MongoDB shell version: 3.0.4 connecting to: test 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: 2015-07-21T19:55:26.318+0800 I STORAGE [initandlisten] 2015-07-21T19:55:26.318+0800 I STORAGE [initandlisten] ** WARNING: Readahead for /home/mongodb-linux-x86_64-3.0.4/data/ is set to 4096KB 2015-07-21T19:55:26.318+0800 I STORAGE [initandlisten] ** We suggest setting it to 256KB (512 sectors) or less 2015-07-21T19:55:26.318+0800 I STORAGE [initandlisten] ** http://dochub.mongodb.org/core/readahead 2015-07-21T19:55:26.551+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2015-07-21T19:55:26.551+0800 I CONTROL [initandlisten] 2015-07-21T19:55:26.552+0800 I CONTROL [initandlisten] 2015-07-21T19:55:26.552+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2015-07-21T19:55:26.552+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2015-07-21T19:55:26.552+0800 I CONTROL [initandlisten] >五、关闭
相关推荐
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09
jaylong 2020-08-19
大秦铁骑 2020-08-19
thatway 2020-08-19