Hive基本操作

一.Hive基本操作

1.启动hive
bin/hive
2.查看数据库
show databases;
3.打开默认数据库
use default;
4.显示default数据库中的表
show tables;
5.创建一张表
create table student(id int, name string) ;
6.显示数据库中有几张表
show tables;
7.查看表的结构
desc student;
8.向表中插入数据
insert into student values(1001,"ss1");
9.查询表中数据
select * from student;
10.退出hive
quit;

二.hive常用交互命令

1.“-e”不进入hive的交互窗口执行sql语句
bin/hive -e "select id from student;"

image.png

2.“-f”执行脚本中sql语句
(1)在/opt/module/datas目录下创建hivef.sql文件
touch hive.sql

文件中写入正确的sql语句

select * from student;
(2)执行文件中的sql语句
bin/hive -f /opt/module/datas/hive.sql
(3)执行文件中的sql语句并将结果写入文件中(注:可能含有其他的表信息,如表头)
bin/hive -f /opt/module/datas/hive.sql  > /opt/module/datas/hive_result.txt

三.Hive其他命令操作

1.退出hive窗口:
exit;
quit;

在新版的oracle中没区别了,在以前的版本是有的:
exit:先隐性提交数据,再退出;
quit:不提交数据,退出;

2.在hive cli命令窗口中如何查看hdfs文件系统
dfs -ls /;
3.在hive cli命令窗口中如何查看linux本地系统
! ls /opt/module/datas;

4.查看在hive中输入的所有历史命令
(1)进入到当前用户的根目录/root或/home/itstar
(2)查看. hivehistory文件
cat .hivehistory

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值