Hive学习笔记二

时间:2020-01-25 19:24:32   收藏:0   阅读:92

Hive常见属性配置

2)重新启动hive,对比配置前后差异

配置前:

技术分享图片

配置后:

技术分享图片

将本地库文件导入Hive案例

需求:将本地/opt/module/datas/student.txt这个目录下的数据导入到hive的student(id int, name string)表中。
//1)在/opt/module/目录下创建datas
[itstar@bigdata111module]$ mkdir datas

//2)在/opt/module/datas/目录下创建student.txt文件并添加数据
[itstar@bigdata111datas]$ touch student.txt
[itstar@bigdata111datas]$ vi student.txt
1001    zhangshan
1002    lishi
1003    zhaoliu
//注意以tab键间隔。
//1)启动hive
[itstar@bigdata111hive]$ bin/hive

//2)显示数据库
hive>show databases;

//3)使用default数据库
hive>use default;

//4)显示default数据库中的表
hive>show tables;

//5)删除已创建的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/hive/mydata/student.txt' into table student;

//8)Hive查询结果
hive> select * from student;

Hive常用交互命令

[itstar@bigdata111hive]$ bin/hive -e "select id from student;"
//1)在/opt/module/datas目录下创建hivef.sql文件
[itstar@bigdata111datas]$ touch hivef.sql
----------------------
//文件中写入正确的sql语句
select *from student;

//2)执行文件中的sql语句
[itstar@bigdata111hive]$ bin/hive -f /opt/module/datas/hivef.sql

//3)执行文件中的sql语句并将结果写入文件中
[itstar@bigdata111hive]$ bin/hive -f /opt/module/datas/hivef.sql  > /opt/module/datas/hive_result.txt

Hive其他命令操作

hive(default)>exit;
hive(default)>quit;

//在新版的oracle中没区别了,在以前的版本是有的:
//exit:先隐性提交数据,再退出;
//quit:不提交数据,退出;
hive(default)>dfs -ls /;
hive(default)>! ls /opt/module/datas;
//1)进入到当前用户的根目录/root或/home/itstar
//2)查看. hivehistory文件
[itstar@bigdata111~]$ cat .hivehistory

参数配置方式

hive>set;

??上述三种设定方式的优先级依次递增。即配置文件<命令行参数<参数声明。注意某些系统级的参数,例如log4j相关的设定,必须用前两种方式设定,因为那些参数的读取在会话建立以前已经完成了。

原文:https://www.cnblogs.com/nthforsth/p/12232322.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!