hive mysql命令,Hive数据库常用命令

收藏一些Hive数据库常用命令,方便平时准备测试数据集。

查看库、创建普通Hive表:

show databases;

user lch_databases;

show tables;

create table lch_user_table(

int id,

name varchar(8),

birthday date,

salary double(24.7),

dd1 decimal(18,4)

);

alert table lch_user_table add columns(性别 string comment '男女');

修改Hive表

alert table lch_user_table RENAME TO new_name;

alert table lch_user_table ADD COLUMNS (col_spec[, col_spec ...]);

alert table lch_user_table ADD COLUMNS(性别 string comment 男女');

alert table lch_user_table DROP [COLUMN] column_name;

alert table lch_user_table CHANGE column_name new_name new_type;

创建分区Hive表:

create table lch_test_table(

order_number string,

event_time string )

PARTITIONED BY(event_month string)

ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

(1) 单分区建表

单分区表,按天分区,在表结构中存在id,content,dt三列。以dt为文件夹区分

create table day_table (id int, content string) partitioned by (dt string);

(2) 双分区建表

双分区表,按天和小时分区,在表结构中新增加了dt和hour两列。先以dt为文件夹,再以hour子文件夹区分

create table day_hour_table (id int, content string) partitioned by (dt string, hour string);

向有分区的表插入数据

(1) 覆盖现有分区数据,如果没有该指定分区,新建该分区,并且插入数据

INSERT OVERWRITE TABLE 库名.表名 PARTITION(dt='2018-09-12',name='Tom', ...)

SELECT ... FROM 库名.表名 where...

(2) 向现有的分区插入数据 (之前的数据不会被覆盖)

INSERT INTO TABLE 库名.表名 PARTITION(dt='2018-09-12',name='Tom',...)

SELECT ... FROM 库名.表名 WHERE ...

向无分区的表插入数据

(1) 覆盖原有表里的数据,命令和有分区的表类似,只是去掉后面的

PARTITION(dt=' ',name=' ')

insert overwrite table 库名.表名

select ... frome 库名.表名 where...

(2) 向现有的表插入数据 (之前的数据不会被覆盖)

insert into talbe 库名.表名

select ... from 库名.表名 where ...

insert into table lch_user_table values

('Lucy','2019-9-18',13493.13,0.12,'女');

跨库复制表

CREATE TABLE NEWDB.NEW_TABLE2 AS select * from OLDDB.OLD_TABLE2;

批量执行命令行

beeline -e "select count() from user;" >>output.txt

beeline -e "select count() from info;" >>output.txt

beeline -e "use bicoredata;" "show tables;" >>output.txt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值