黑猴子的家:将本地文件导入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;

你可能感兴趣的:(Hive)