目录
一:启动hive
注意启动hive之前请启动Hadoop
如何启动Hadoop
cd /usr/local/hadoop/sbin #进入相关目录下面
./start-dfs.sh #判断是否启动成功使用jps
启动hive:
cd /usr/local/hive
./bin/hive
二 :hive介绍
1.hive本质:将HQL转化为MapReduce程序
2.hive中select不走MR,走元数据
3.基本数据类型:INT,BIGINT,DOUBLE,STRING
hive的string类型相当于数据库中的varchar类型
4.hive中集合数据类型有
Map, Array, Struct
支持类型转换
三:创建数据库和数据表
创建数据库
create table if not exists hive;
#查看数据库
show databases;
# 查看数据库中以h开头的数据库
show databases like 'h.*';
# 描述数据库位置等信息
describe databases;
# 使用某个数据库
use name;
创建表
create table if not exists usr3(
name string,
pwd string,
address struct<street:string,city:string,state:string,zip:int>,
identify map<int,tinyint>)
partitioned by(city string,state string);
# 展示所有表
show tables in hive;
# 查看以u开头的表
show tables 'u.*';
#查看表的相关信息
describe hive.usr;
#重命名表
alter table usr rename to custom
四:向表中装载数据
这里我们以只有两个属性的简单表为例来介绍。首先创建表stu和course