show databases;create database [if not exists] test01;
create database test02 comment 'this is a database' location '/myCreateDatabase/';其中方括号中的内容为可选项,意思是:如果不存在数据库test01则创建。
第二条创建语句comment选项后指定的是该数据库的备注信息,原生的hive不支持中文,想要支持中文要修改国际化的配置文件,location后指定的是数据库的存储路径,该路径为hdfs上的路径。
describe database test01;use test01;
create table table01(name String , age int);
create table table02(name String , age int) row format delimited fields terminated by ',';其中第一条创建语句是创建一个简单的表,第二条创建语句是创建带有指定列分隔符的表,这个分隔符是在数据导入的时候有用。
use test01;
desc table01;create table table03(name String) partitioned by (age int);创建分区表的时候,分区表字段不能使用前面使用过的字段,并且要写上字段类型。这里以age作为分区。
create table table04(name String ,age int) clustered by (name) into 3 buckets;以name分桶,分3个桶。
desc查看表的信息不详细,分桶表和普通的表看不出区别,所以使用desc formatted table04查看。
Table Type: MANAGED_TABLE 表示这是一个内部表。
Num Buckets: 3 表示有3个分桶。
Bucket Columns: [name] 分桶字段。
drop table [if exists] table01;方括号中的内容为可选项
Hive内部执行流程:解析器(解析SQL语句)、编译器(把SQL语句编译成MapReduce程序)、优化器(优化MapReduce程序)、执行器(将MapReduce程序运行的结果提交到HDFS)