MongoDB for Linux 的安装

项目参数
操作系统CentOS 6.7
系统内存2GB
MongoDB版本4.0.16

下载软件

登录MongoDB官网,选择社区版软件下载学习使用。
在这里插入图片描述

选好后直接Download即可
在这里插入图片描述

安装软件

1. ftp先上传下载好的软件压缩包到Linux系统中

sftp> put mongodb-linux-x86_64-rhel62-4.0.16.tar
Uploading mongodb-linux-x86_64-rhel62-4.0.16.tar to /root/mongodb-linux-x86_64-rhel62-4.0.16.tar
  100% 284260KB  31584KB/s 00:00:09     
/Users/ivy_dong/Downloads/mongodb-linux-x86_64-rhel62-4.0.16.tar: 291082240 bytes transferred in 9 seconds (31584 KB/s)
sftp> 

查看压缩包,已顺利上传

[root@pg01 ~]# ll mongodb-linux-x86_64-rhel62-4.0.16.tar 
-rw-r--r--. 1 root root 291082240 Mar 19  2020 mongodb-linux-x86_64-rhel62-4.0.16.tar

2. 解压安装包

[root@pg01 ~]# tar -xvf mongodb-linux-x86_64-rhel62-4.0.16.tar 

3. 进入解压有目录中

[root@pg01 ~]# mv mongodb-linux-x86_64-rhel62-4.0.16 mongodb
[root@pg01 ~]# cd mongodb
[root@pg01 mongodb]# ls
bin  LICENSE-Community.txt  MPL-2  README  THIRD-PARTY-NOTICES  THIRD-PARTY-NOTICES.gotools

4. 安排数据存放位置

[root@pg01 ~]# mkdir -p /mongodb/data

启动MongoDB

[root@pg01 bin]# ./mongod --port 27017 --dbpath=/mongodb/data

启动过程中,会有较多的输出。其中看到以下字样说明服务已启动。之后停住不动了。暂时不管。

2020-03-15T03:52:17.672+0800 I NETWORK  [initandlisten] waiting for connections on port 27017

2020-03-15T03:52:18.031+0800 I INDEX    [LogicalSessionCacheRefresh] build index done. 

验证安装

登录MongoDB

再打开一个session,我们就可以登录进MongoDB了

[root@pg01 ~]# cd mongodb/bin/
[root@pg01 bin]# ./mongo
.... (省略)
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

>  
  • 查看所有数据库
## 方法一
> show databases;
admin   0.000GB
config  0.000GB
local   0.000GB

## 方法二
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
  • 使用、选择数据库
> use local;
switched to db local
  • 查看当前所在库
> db
local

创建新数据库

使用一个不存在的数据库

> use dong
switched to db dong

这里却没有dong,因为mongo不显示没有集合的库

> show databases;
admin   0.000GB
config  0.000GB
local   0.000GB

创建集合(创建表)

  • 查看当前库中的集合
> show collections;
startup_log

> show tables;
startup_log
  • 创建集合 (建表)区分大小写
> db.createCollection("t_user");
{ "ok" : 1 }
> show tables;
t_user
> 
> show databases;
admin   0.000GB
config  0.000GB
dong    0.000GB
local   0.000GB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值