常用Hive命令速查(全)

--hive模糊搜索表:
show tables like '*name*';

--查看表结构信息:
desc table_name; desc formatted table_name;

--查看分区信息:
show partitions table_name;

--加载本地文件:
load data local inpath '/xxx/test.txt' overwrite into table dm.table_name;

--从查询语句给table插入数据:
insert overwrite table table_name partition(dt) select * from table_name;

--导出数据到本地系统:
insert overwrite local directory '/tmp/text' select a.* from table_name a order by 1;

--hive修改表名:
alter table old_table_name rename to new_table_name;

--hive复制表结构:
create table new_table_name like table_name;

--hive添加字段:
alter table table_name add columns(columns_values bigint comment 'comm_text');

--hive修改字段:
alter table table_name change old_column new_column string comment 'comm_text';

--删除分区:
alter table table_name drop partition(dt='2022-04-30');

--添加分区:
alter table table_name add partition (dt='2022-04-30');

--删除空数据库:
drop database myhive2;

--强制删除数据库:
drop database myhive2 cascade;

--删除表:
drop table test_table5;

--清空表:
truncate table test_table6;



--向hive表中加载数据
--直接向分区表中插入数据:
insert into table test_table partition(month ='202207') values ('001','002','100');

--通过load方式加载数据:
load data local inpath '/export/data/hivedatas/test_table.csv' overwrite into table test_table partition(month='201806');

--通过查询方式加载数据:
insert overwrite table test_table2 partition(month = '202206') select s_id,c_id,s_test_table from test_table1;

--查询语句中创建表并加载数据:
create table test_table2 as select * from test_table1;

--在创建表是通过location指定加载数据的路径:
create external table test_table6 (s_id string,c_id string,s_test_table int) row format delimited fields terminated by ',' location '/mytest_table';

--export导出与import导入hive表数据(内部表操作):
create table test_table2 like test_table; --依据已有表结构创建表
export table test_table to '/export/test_table';
import table test_table2 from '/export/test_table';



--hive表中数据导出(insert导出)
--将查询的结果导出到本地:
insert overwrite local directory '/export/data/exporthive' select * from test_table;

--将查询的结果格式化导出到本地:
insert overwrite local directory '/export/data/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from student;

将查询的结果导出到HDFS上(没有local):
insert overwrite directory '/export/data/exporthive' row format delimited fields terminated by '\t' collection items terminated by '#' select * from test_table;

--hive表中数据导出(Hadoop命令导出)
--Hadoop命令导出到本地:
dfs -get /export/data/exporthive/000000_0 /export/data/exporthive/local.txt;

--hive表中数据导出(hive shell 命令导出)
--hive shell 命令导出(hive -f/-e 执行语句或者脚本 > file)
hive -e "select * from myhive.test_table;" > /export/data/exporthive/test_table.txt
hive -f export.sh > /export/data/exporthive/test_table.txt

--export导出到HDFS上:
export table test_table to '/export/exporthive/test_table';



--创建表时指定的一些属性:
--字段分隔符:
row format delimited fields terminated by '\t'

--行分隔符:
row format delimited lines terminated by '\n'

--文件格式为文本型存储:
stored as textfile


--命令行操作:
hive -e 'select table_cloum from table'执行一个查询,在终端上显示mapreduce的进度,执行完毕后,最后把查询结果输出到终端上,接着hive进程退出,不会进入交互模式

hive -S -e 'select table_cloum from table' -S,终端上的输出不会有mapreduce的进度,执行完毕,只会把查询结果输出到终端上。

Hive SQL 语法大全 整理

https://blog.csdn.net/weixin_40983094/article/details/110476517?spm=1001.2014.3001.5501 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值