Hive环境配置及建表初探

Hive环境配置及建表初探

实验操作分为三部分:配置mysql环境,配置hive环境,和使用hive命令处理文本数据

一、配置mysql环境

1.安装mysql软件
	sudo apt-get install mysql-server
2.创建Hive数据库
	mysql> create database hive default character set latin1;
3.创建hive用户并授权

用户名为hive,密码为123456,该设置在配置hive环境时会用到

	mysql>  grant all privileges on hive.* to hive@'%' identified by '123456';

二、配置hive环境

1.下载相关文件

从http://mirrors.shuosc.org/apache/hive/stable/ 上下载 apache-hive-1.2.2-bin.tar.gz 文件,解压到自定义目录

2.修改/etc/profile文件配置hadoop和hive环境变量

如图所示

3.创建和改写配置文件

改写/apache-hive-1.2.2-bin/conf 的相关文件

hive-default.xml.template 改为 hive-site.xml
hive-env.sh.template 改为 hive-env.sh
hive-log4j2.properties.template 改为 hive-log4j2.properties              
hive-exec-log4j2.properties.template 改为 hive-exec-log4j2.properties

在hive-site.xml中修改图示内容,共6处

1.配置hive用户

2.设置连接密码


3.设置Mysql为数据库驱动


4.设置 metanode连接的jdbc地址


5.更改路径


6.因为报错所以新加的,应该也是某个路径问题

4.添加jar包

在**/apache-hive-1.2.2-bin/lib** 中添加 mysql-connector-java-5.1.19-bin.jar(需要另外下载,并且版本不宜过高)

三、输入词频统计文本文件进行hive操作

1.输入文件到hdfs上,存储为/tmp/wordcount.txt

命令不再赘述,截图如下

2.第一次登陆初始化
	./schematool -dbType mysql -initSchema
3.进入hive

进入到hive目录

	cd hadoop_installs/hadoop-2.7.4/apache-hive-1.2.2-bin/bin

启动hive

	./hive

在Hive的命令行模式下创建表

	hive> create table NewsWord(count int comment 'frequency',word string comment 'value') row format delimited fields terminated by '\t';

查看表

	hive> show tables;

导入hdfs上的 /temp/wordcount.txt

	hive> load data inpath '/tmp/wordcount.txt' into table NewsWord;

查看内容

	hive> select * from newsword;

结果截图

挑选count>=8000的数据

	hive> select * from newsword where count >8000;

上述简单地使用hive进行了实验。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值