show databases; -- 查看所有数据库

use 数据库;     -- 进入某个数据库

select current_database(); -- 查看当前使用的数据库

show tables;    -- 显示所有表

show tables like '*tb_site*' -- 显示特定表

show partitions 表名; -- 显示表的所有分区

desc tab_name; -- 查看表结构

desc formatted tab_name; -- 查看表结构详细信息(文件地址)

查看表在HDFS中存放的数据文件(hadoop操作):
hdfs dfs -ls hdfs://hadoop001:8020/user/hive/warehouse/tab_name(文件地址) show create table_name; -- 显示创建表的语句 select * from tab_name limit 2; -- 查询前n行 创建分区表:
create table if not exists tab_name(
id int,
name string
)PARTITIONED BY (deal_day string) -- deal_day 分区字段
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\u0001' -- 分隔符
LINES TERMINATED BY '\n' -- 换行符
STORED AS TEXTFILE -- 数据存储格式
LOCATION '/data/tab_name' -- 文件存储地址 create table as select 指定数据存储格式创建表 create table tab_name stored as textfile as
select * from tab_name2 insert overwrite table 覆盖分区式插入数据
注:在表结构发生变化(增加、删除字段)之后,需要删除分区才能更新数据。 insert overwrite table tab_name partition(deal_day='某个分区日期')
select * from tab_name2 自动分区插入数据
insert overwrite table tab_name partition(deal_day)
select id,name,deal_day from tab_name2 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;-- 修改字段 alter table table_name replace columns (col1 int,col2 string,col3 string);-- 删除字段(COLUMNS中只放保留的字段) drop table table_name;-- 删除表 alter table table_name drop if exists partition (deal_day='某个分区日期'); -- 删除分区 drop database if exists db_name; -- 删除库 drop database if exists db_name cascade; -- 强制删除库 drop table if exists table_name; -- 删除表 truncate table table_name; -- 清空表 insert overwrite table table_name select * from table_name where 1=0; -- 清空表 alter table table_name drop partition (deal_day<='某个日期'); -- 删除分区 insert overwrite table table_name select * from table_name where id>='20'; -- 按条件删除数据,删除id小于20的数据,保留id大于等于20的数据 hive -e "sql语句" -- 将查询结果打印在控制台上 hive -e "sql语句" > xxx.txt -- 将查询结果写入到txt文件中

hive 之 常用基本操作的更多相关文章

  1. 2 hive的使用 + hive的常用语法

    本博文的主要内容有: .hive的常用语法 .内部表 .外部表 .内部表,被drop掉,会发生什么? .外部表,被drop掉,会发生什么? .内部表和外部表的,保存的路径在哪? .用于创建一些临时表存 ...

  2. MatplotLib常用基本操作

    本文记录matlibplot常用基本操作,都是基本功能,不涉及复杂联合操作,其中各用法详细用法可参考官网: 1. 基本画图操作 ##mofan_matplotlib.pyplot import mat ...

  3. Hive SQL 常用日期

    Hive SQL 常用日期 原文地址:Hive SQL常用日期函数 Hive SQL 常用日期 注意: MM DD MO TU等要大写 已知日期 要求日期 语句 结果 本周任意一天 本周一 selec ...

  4. hive的使用 + hive的常用语法

    本博文的主要内容有: .hive的常用语法 .内部表 .外部表 .内部表,被drop掉,会发生什么? .外部表,被drop掉,会发生什么? .内部表和外部表的,保存的路径在哪? .用于创建一些临时表存 ...

  5. hive sql常用整理-hive引擎设置

    遇到个情况,跑hive级联insert数据报错,可以尝试换个hive计算引擎 hive遇到FAILED: Execution Error, return code 2 from org.apache. ...

  6. hive的常用操作

    1.hive的数据类型 tinyint/smallint/int/bigint tinyint:从 0 到 255 的整型数据 smallint:从 0 到 65535 的整型数据 int:从 0 到 ...

  7. hive & hive beeline常用参数

    Hive 1参数如下: usage: hive -d,--define <key=value> Variable substitution to apply to Hive command ...

  8. 二、hive shell常用命令

    在使用hive shell之前我们需要先安装hive,并启动hdfs 请参考:https://www.cnblogs.com/lay2017/p/9973298.html hive shell 我们先 ...

  9. Hive Shell常用操作

    1.Hive非交互模式常用命令: 1) hive -e:从命令行执行指定的HQL,不需要分号: % hive -e 'select * from dummy' > a.txt 2) hive – ...

随机推荐

  1. 在html页面通过绝对地址显示图片

    1.编辑tomcat中conf目录下的server.xml文件,在<Host></Host>中添加如下代码段 <Context path="/D" d ...

  2. Git remote 远程仓库链接管理

    SVN 使用单个集中仓库作为开发人员的通信枢纽,通过在开发人员的工作副本和中央仓库之间传递变更集来进行协作. 这与 Git 的分布式协作模型不同,后者为每个开发人员提供了自己的仓库副本,并具有自己的本 ...

  3. [BUUCTF]PWN——pwnable_hacknote

    pwnable_hacknote 附件 步骤: 例行检查,32位程序,开启了nx和canary保护 本地试运行看一下大概的情况,熟悉的堆的菜单 32位ida载入 add() gdb看一下堆块的布局更方 ...

  4. [BUUCTF]PWN2——rip

    [BUUCTF]PWN2-rip 题目网址:https://buuoj.cn/challenges#rip 步骤: 例行检查附件,64位程序,没有开启任何保护 nc一下,看看输入点的提示字符串,让我们 ...

  5. [BUUCTF]PWN——jarvisoj_tell_me_something

    jarvisoj_tell_me_something 附件 步骤: 例行检查,64位程序,开启了NX保护 运行一下程序,看看程序的大概流程 64位ida载入,shift+f12检索程序里的字符串 看到 ...

  6. SourceTree Git可视化管理工具通过 ssh 密钥登录

    整个流程分三步:① 生成SSH密钥:② Github/Gitee/Coding 代码托管平台绑定公钥:③ SourceTree 拉取代码 1.生成 SSH 密钥 这里直接使用 SourceTree 来 ...

  7. Nginx加载新的模块,编译报错记录

    参考:https://www.cnblogs.com/Leechg/p/9969000.html ---------如下我的操作记录--------------- nginx -V查看当前nginx信 ...

  8. git pull 拉取报错:fatal: refusing to merge unrelated histories

    fatal: refusing to merge unrelated histories(拒绝合并不相关的历史) 使用 git pull origin master --allow-unrelated ...

  9. Spring支持的常用数据库传播属性和事务隔离级别

    一.事务的传播属性 1.propagation:用来设置事务的传播行为,一个方法运行在了一个开启了事务的方法中时,当前方法是使用原来的事务还是开启一个新的事务. (1)propagation.REQU ...

  10. table中tr、td标签设置只读,不能修改(readonly属性)

    在不能修改的位置加上代码:onselectstart="return false" οnselect="document.selection.empty()" ...