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)

猜你喜欢

转载自www.cnblogs.com/jhxxb/p/11608568.html