查看hive数据库列表
show databases;
新建hive数据库test_2019
create database test_2019;
切换至数据库进行操作
use test_2019;
查看已有表的建表语句
desc create table table_name;
查看表清单
show tables;
查看数据:
select * from table_name
查看表结构:
desc formatted table_name
删除表:
drop table table_name
创建外部分区表:
create external table table_name(id int,name string,city array)
Partitioned by (p_date string) row format delimited fields terminated by ‘\t’ collection items terminated by ‘,’ stored as textfile;
内部表:
create table userinfo2(id int,name string,city array) row format delimited fields terminated by ‘\t’ collection items terminated by ‘,’ stored as textfile;
字段与字段之间用换行号分割,字段内部之间的数据用逗号分割,指定文件存储的格式(纯文本的话可以用textfile)
加载数据:
insert overwrite table table_name1 partition (p_date=‘xxxx-xx-xx’) select * from table_name2