Hive(1)--本地derby安装与配置

Hive–本地derby安装和配置

一、Hive安装地址

1.Hive官网地址

http://hive.apache.org/

2.文档查看地址

https://cwiki.apache.org/confluence/display/Hive/GettingStarted

3.下载地址

http://archive.apache.org/dist/hive/

4.github地址

https://github.com/apache/hive

二、 Hive安装部署

hive 官网上提供了三种配置方式,本地derby 、本地Mysql、远程Mysql。分别如下:

2.1.Hive安装及配置

(1)把apache-hive-1.2.1-bin.tar.gz上传到linux的/opt/software目录下

(2)解压apache-hive-1.2.1-bin.tar.gz到/opt/module/目录下面

[root@hadoop102 software]$ tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/

(3)修改apache-hive-1.2.1-bin.tar.gz的名称为hive

[root@hadoop102 module]$ mv apache-hive-1.2.1-bin/ hive

(4)修改/opt/module/hive/conf目录下的hive-env.sh.template名称为hive-env.sh

[root@hadoop102 conf]$ mv hive-env.sh.template hive-env.sh

(5)配置hive-env.sh文件

​ (a)配置HADOOP_HOME路径

export HADOOP_HOME=/opt/module/hadoop-2.7.2

​ (b)配置HIVE_CONF_DIR路径

export HIVE_CONF_DIR=/opt/module/hive/conf
2.2 Hadoop集群配置

(1)必须启动hdfs和yarn

[root@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh

[root@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh

(2)在HDFS上创建/tmp和/user/hive/warehouse两个目录并修改他们的同组权限可写

[root@hadoop102 hadoop-2.7.2]$ bin/hadoop fs -mkdir /tmp

[root@hadoop102 hadoop-2.7.2]$ bin/hadoop fs -mkdir -p /user/hive/warehouse 

[root@hadoop102 hadoop-2.7.2]$ bin/hadoop fs -chmod g+w /tmp

[root@hadoop102 hadoop-2.7.2]$ bin/hadoop fs -chmod g+w /user/hive/warehouse
2.3 配置环境变量
  • 修改环境变量/etc/profile:
[root@hadoop102 hadoop-2.7.2]$  vim /etc/profile
 export HIVE_HOME=/opt/module/hive
 export PATH=$PATH:$HIVE_HOME/bin
  • 执行source /etc.profile

  • 执行hive --version

[root@hadoop102 hadoop-2.7.2]$ hive --version

有hive的版本显现,安装成功!

三、Hive基本操作

(1)启动hive

[root@hadoop102 hive]$ bin/hive

(2)查看数据库

hive> show databases;

(3)打开默认数据库

hive> use default;

(4)显示default数据库中的表

hive> show tables;

(5)创建一张表

hive> create table student(id int, name string);

(6)显示数据库中有几张表

hive> show tables;

(7)查看表的结构

hive> desc student;

(8)向表中插入数据

hive> insert into student values(1000,"ss");

(9)查询表中数据

hive> select * from student;

(10)退出hive

hive> quit;

四、 将本地文件导入Hive案例

需求

将本地/opt/module/datas/student.txt这个目录下的数据导入到hive的student(id int, name string)表中。

4.1.数据准备

在/opt/module/datas这个目录下准备数据

(1)在/opt/module/目录下创建datas

[root@hadoop102 module]$ mkdir datas

(2)在/opt/module/datas/目录下创建student.txt文件并添加数据

[root@hadoop102 datas]$ touch student.txt

[root@hadoop102 datas]$ vi student.txt

1001 zhangshan

1002 lishi

1003 zhaoliu

注意 以tab键间隔。

4.2.Hive实际操作

(1)启动hive

[root@hadoop102 hive]$ bin/hive

(2)显示数据库

hive> show databases;

(3)使用default数据库

hive> use default;

(4)显示default数据库中的表

hive> sh;

(5)删除已创 tables建的student表

hive> drop table student;

(6)创建student表, 并声明文件分隔符’\t’

hive> create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED

BY ‘\t’;

(7)加载/opt/module/datas/student.txt 文件到student数据库表中。

hive> load data local inpath ‘/opt/module/datas/student.txt’ into table student;

(8)Hive查询结果

hive> select * from student;

OK

1001 zhangshan

1002 lishi

1003 zhaoliu

Time taken: 0.266 seconds, Fetched: 3 row(s)

以上是本地derby 安装配置,只能支持一个用户登录,用起来不方便,因此需要配置本地Mysql数据库。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值