Hive基本命令

启动hive服务端程序: hive --service metastore

启动hive客户端程序: hive --service hiveserver2 (java客户端可以调用此hive服务)

进入命令模式:

./hive

查看库

show databases;

创建库

create database hive; 

创建表

use hive;
create table bus_receiver(a string,b int); 
show tables;                --查看表

desc 表名;                # 显示表结构
show partitions 表名;     # 显示表名的分区
show create table_name;   # 显示创建表的结构
drop table table_name;    # 删除表  

# 建表语句
# 内部表
use xxdb; create table xxx;
# 创建一个表,结构与其他一样
create table xxx like xxx;
# 外部表
use xxdb; create external table xxx;
# 分区表
use xxdb; create external table xxx (l int) partitoned by (d string)
# 内外部表转化
alter table table_name set TBLPROPROTIES ('EXTERNAL'='TRUE'); # 内部表转外部表
alter table table_name set TBLPROPROTIES ('EXTERNAL'='FALSE');# 外部表转内部表

# 表结构修改
# 重命名表
use xxxdb; alter table table_name rename to new_table_name;
# 增加字段
alter table table_name add columns (newcol1 int comment ‘新增’);
# 修改字段
alter table table_name change col_name new_col_name new_type;
# 删除字段(COLUMNS中只放保留的字段)
alter table table_name replace columns (col1 int,col2 string,col3 string);
# 删除表
use xxxdb; drop table table_name;
# 删除分区
# 注意:若是外部表,则还需要删除文件(hadoop fs -rm -r -f  hdfspath)
alter table table_name drop if exists partitions (d='2016-07-01');

查询分区信息: show partitions 表名

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值