Hive将本地文件导入Hive案例

您所在的位置:网站首页 hive导入hdfs文件 Hive将本地文件导入Hive案例

Hive将本地文件导入Hive案例

2023-10-18 06:45| 来源: 网络整理| 查看: 265

0.需求:

将本地/opt/module/datas/student.txt这个目录下的数据导入到hive的student(id int, name string)表中。

1.数据准备:在/opt/module/datas/student.txt这个目录下准备数据 (1)在/opt/module/目录下创建datas mkdir datas (2)在/opt/module/datas/目录下创建student.txt文件并添加数据 touch student.txt vi student.txt

添加内容:

1001 zhangshan 1002 lishi 1003 zhaoliu

注意以tab键间隔。

2.Hive实际操作 (1)启动hive bin/hive (2)显示数据库 show databases; (3)使用default数据库 use default; (4)显示default数据库中的表 show tables; (5)删除已创建的student表 drop table student; (6)创建student表, 并声明文件分隔符’\t’ create table student(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'; (7)加载/opt/module/datas/student.txt 文件到student数据库表中。 load data local inpath '/opt/module/datas/student.txt' into table student; (8)Hive查询结果 select * from student;

image.png

可能是编码的问题吧,留个坑 在hdfs中就是正常的,所以应该是格式问题



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3