本文所需环境如下:
操作系统:CentOS 7.2 64位
Hive版本:2.1.1
JDK版本:jdk1.8.0_131
Hadoop版本:2.8.1
hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:/usr/local/src/app/apache-hive-2.1.1-bin/metastore_db;create=true</value>
</property>
</configuration>
第一次进入hive,查看默认数据库
第一次进入hive,查看默认数据库
创建一个自己的数据库park
创建一个自己的数据库park
使用park,创建一张表stu,插入一条数据
使用park,创建一张表stu,插入一条数据
查看当前stu数据
查看当前stu数据
查看hdfs中的hive数据
查看hdfs中的hive数据
自己手工创建1.txt,上传到hive的stu表目录下
自己手工创建1.txt,上传到hive的stu表目录下
在hive下,查看手动上传数据
在hive下,查看手动上传数据
发现显示为NULL,原因是hive不知文件的分割符,不能做出判断
手动删除hdfs中的stu表目录
手动删除hdfs中的stu表目录
但是hive中并没有删除stu,因为stu的元数据信息不在hdfs上,在本地
hive中并没有删除stu
在hive中drop掉,删除元数据
在hive中drop掉,删除元数据
创建指定分隔符的表stu
创建指定分隔符的表stu
再次上传1.txt
再次上传1.txt
在hive中查看
在hive中查看
再次上传2.txt
再次上传2.txt
使用另一个命令加载
使用另一个命令
查看表结构
查看表结构
创建一个相同结构的表
创建一个相同结构的表
把stu表中的数据,存入stu2
hive> load data local inpath '/root/2.txt' into table stu;
把stu表中的数据,存入stu2
把stu表中的数据,存入stu2
把查询结果写入本地目录
hive> insert overwrite local directory '/root/stu' row format delimited fields terminated
by ' ' select * from stu;
把查询结果写入本地目录
把查询结果写入本地目录
把查询结果写入hdfs
hive> insert overwrite directory '/stu' row format delimited fields terminated by ' ' select * from stu;
把查询结果写入hdfs
把查询结果写入hdfs
对表stu重命名stu1
对stu重命名stu1
为stu1增加一个字段
为stu1增加一个字段
退出hive
退出hive