黑猴子的家:将本地文件导入Hive的基础demo

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

1、数据准备

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

[victor@node1 module]$ mkdir datas

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

[victor@node1 datas]$ touch student.txt
[victor@node1 datas]$ vim student.txt
1001    zhangshan
1002    lishi
1003    zhaoliu
注意:以tab键间隔。

2、hive实际操作

(1)启动hive

[victor@node1 hive]$ bin/hive

(2)显示数据库

hive> show databases;

(3)使用default数据库

hive> use default;

(4)显示default数据库中的表

hive> show tables;

(5)创建student表, 并声明文件分隔符’\t’

hive> create table student(id int, name string) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';

(6)加载/opt/module/datas/student.txt 文件到student数据库表中

hive> load data local inpath '/opt/module/datas/student.txt' into table student;

3、hive查询结果

(1)查询数据库

hive> select * from student;

(2)查询id

hive> select id from student;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容