hive基本操作大全

大一大二 hive基本命令 持续更新

1.创建数据库(判断是否存在)

create database if not exists [d_name];

2.删除数据库(判断是否存在)

drop tablese if exists [d_name];

3.通配符显示数据库

show databases like '***' ;

4.显示数据库详细信息

desc database extended [d_name];

5.建表

create table [t_name] (name string,age int)

row format delimited

fields terminated by ' \t' ;

6.创建相同结构的表 ,并存在指定地点

create table [t1_name] like  [t2_name] location '/opt/data';

7.导入虚拟机中得数据

load data local inpath[虚拟机文件位置加''] into table [t_name]

fs->hive:去掉local

load data inpath 'hadoop位置' into table _

例:

load data local inpath'/opt/data/chanpin.txt' into table aa;

删除所有数据,并导入

load data local inpath[虚拟机文件位置加''] overwrite  into table [t_name]

8.创建外部表,创建后面添加external

create external table student(s_id string,s_name string,s_birth string,s_sex string)row format delimited fields terminated by '\t';

9.查看是内部表还是外部表

desc formatted t_name;

10.创建带数组得表

create table t_name(id int,d_name [struct:字段类型]<name:string,age:int,weight:double>)

row format delimited

fields terminated

collection items terminated by '\t';

11.内部表和外部表相互转换

alter table [表名] set tblproperties('EXTERNAL'='FALSE/TRUE');

分区表

1.创建分区表

create table [表名] (id int, name string) partitioned by ([与前面不相同的一个字段]) row format delimited fields terminated by '\t';

例子:

create table nian (id int, name string) partitioned by (month string) row format delimited fields terminated by '\t';

**2.查看分区

show partitions [表名];

3.添加/删除一个分区

alter table [表名] add/drop partition(month='2022.10.5');

4.加载数据到分区表中

load data local inpath 'hadoop路径' into table 表名 partition(month=2022.10.5'')

5创建临时表

create temporary table name()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值