Hive-基本操作

安装 Hive:https://www.cnblogs.com/jhxxb/p/11606842.html

# 启动 hive
bin/hive

# 查看数据库
hive> show databases;

# 打开默认数据库
hive> use default;

# 显示 default 数据库中的表
hive> show tables;

# 创建一张表
hive> create table student(id int, name string);

# 显示数据库中有几张表
hive> show tables;

# 查看表的结构
hive> desc student;

# 向表中插入数据
hive> insert into student values(1000,"ss");

# 查询表中数据
hive> select * from student;

# 退出 hive
hive> quit;

将本地文件导入 Hive

cd /opt/
vim student.txt

# 注意以 tab 键间隔
1001    zhangshan
1002    lishi
1003    zhaoliu


# 启动 hive
bin/hive

# 显示数据库
show databases;

# 使用 default 数据库
use default;

# 显示 default 数据库中的表
show tables;

# 删除已创建的 student 表
drop table student;

# 创建 student 表, 并声明文件分隔符’\t’
create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

# 加载/opt/module/data/student.txt 文件到 student 数据库表中。
load data local inpath '/opt/student.txt' into table student;
# Hive 查询结果
select * from student;

OK
1001 zhangshan
1002 lishi
1003 zhaoliu
Time taken: 0.085 seconds, Fetched: 3 row(s)

 

转载于:https://www.cnblogs.com/jhxxb/p/11608568.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值