hive查看表中列的信息命令_大数据之Hive常用命令(DDL)

本文介绍了如何将本地数据导入Hive表,以及Hive的DDL操作,包括创建、查询、修改和删除数据库,以及创建表的详细语法,强调了外部表、表的注释、分区和存储格式等概念。
摘要由CSDN通过智能技术生成

一条一条数据的插入显然是不现实的,现在尝试将txt文件直接导入到hive表student中

需求

将本地/opt/module/data/student.txt 这个目录下的数据导入到 hive 的 student(id int, name

string)表中。

1.数据准备

在/opt/module/data 这个目录下准备数据

(1)在/opt/module/目录下创建 data

root@iZptv27z435ygwZ:/opt/module# mkdir data 

(2)在/opt/module/datas/目录下创建 student.txt 文件并添加数据

root@iZptv27z435ygwZ:/opt/module/data# touch student.txt
root@iZptv27z435ygwZ:/opt/module/data# vi student.txt

1f94d7bb70bf72d3cb7e64ba51f4d627.png

注意以 tab 键间隔。

2.Hive 实际操作

 # 启动 hive

$ bin/hive

# 显示数据库
hive> show databases;

# 使用 default 数据库
hive> use default;

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

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

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

# 加载/opt/module/data/student.txt 文件到 student 数据库表中。
hive> load data local inpath '/opt/module/data/student.txt' into 
table student;

# Hive 查询结果
hive> select * from student;
OK
1001    zhangshan
1002    lishi
1003    zhaoliu
NULL    NULL
Time 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值