Hive第二天——Hive使用
自己的话:黑发不知勤学早,白首方悔读书迟
每天都要保持前进,我势必要有强劲的实力,再跟明天的自己问好。
尽量使用Xshell启动两个窗口连接虚拟机hadoop01,一个在hive下操作,另一个在linux下操作。
一、建表
表定义信息会被记录到hive的元数据中(mysql的hive库)
会在hdfs上的hive库目录中创建一个跟表名一致的文件夹
往表目录中放入文件就有数据了
此时我们进入到hive中:
1.创建表test_1:
hive> create table tset_1(id int,name string);
2.查看test_1表的描述信息
hive> desc test_1;
有两个字段id和name,age
3.创建一个文件,然后上传到hdfs对应的test_1表对应的目录下
[root@hdp02 home]# vi test_1.txt
[root@hdp02 home]# hadoop fs -put test_1.txt /user/hive/warehouse/test_1
到hive上
hive> select * from test_1;
这是因为建表语句是:create table test_1(id string,name string,age int);并没有指定分隔符”,”
4.删掉这个表
hive> drop table test_1;
5.再次创建一个test_1表,三个字段id和name,age用”,”作为分割符
hive>create table test_1(id string,name string,age int)
>row format delimited
>fields terminated by ',';
6.重新上传文件到hdfs对应的test_1表目录下
[root@hdp02 home]# hadoop fs -put test_1.txt /user/hive/warehouse/test_1
到hive上
hive> select * from test_1;
7.再编辑一个文件
[root@hdp02 home]# vi test_1.txt.1
8.上传到test_1表下
[root@hdp02 home]# hadoop fs -put test_1.txt.1 /user/hive/warehouse/test_1
到hive上
hive> select * from test_1;
发现数据添加了进来
二、内部表和外部表(external)
1.内部表
(1)创建表:
hive> create table t_2(id i