大数据-Hive 常用命令

 Hive 启动

~$ hive 

退出

hive>quit;     --退出hive

or

hive> exit;    --exit会影响之前的使用,所以需要下一句kill掉hadoop的进程
>hadoop job -kill jobid

 

选择使用哪个数据库

hive> use database_name;    --使用哪个数据库

 

查看数据表结构

hive> describe tab_name; or desc tab_name;   --查看表的结构及表的路径

 

查看数据库的描述及路径

hive> describe database database_name; 
or
hive> desc database database_name;
 --查看数据库的描述及路径

 

 

 

Hive QL

  • 创建数据库
-- 创建hello_world数据库
create database hello_world; 
-- 如果数据库已经存在就会抛出一个错误信息,使用如下语句可以避免抛出错误信息:
create database if not exists database_name

 

  • 查看所有数据库
show databases;

 

  • 查看所有表
show tables;

 

  • 创建内部表
-- 创建hello_world_inner
create table hello_world_inner
(
    id bigint, 
    account string, 
    name string,
    age int
)
row format delimited fields terminated by '\t';

 

 

  • 创建分区表
create table hello_world_parti
(
    id bigint,
    name string
)
partitioned by (dt string, country string)
;

 

  • 展示表分区
show partitions hello_world_parti;

 

  • 更改表名称
alter table hello_world_parti to hello_world2_parti;

 

  • 删除数据表
hive>drop table t1 ;      --删除表t1
or
hive> drop table if exists t1;

 

  • 可以用下面的命令来修改数据库的路径:
hive> create database database_name location '路径';   

hive> drop database if exists database_name; --删除空的数据库

hive> drop database if exists database_name cascade; --先删除数据库中的表再删除数据库

 

 

  • 导入数据
load data local inpath '/home/deploy/user_info.txt' into table user_info;

 

导入数据的几种方式

比如有一张测试表:

create table hello
(
id int,
name string,
message string
)
partitioned by (
dt string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
;

 

  • 从本地文件系统中导入数据到hive表
load data local inpath 'data.txt' into table hello;

 

  • 从HDFS上导入数据到hive表
  • 从别的表中查询出相应的数据并导入到hive表中
  • 创建表时从别的表查到数据并插入的所创建的表中

 

 

转载于:https://www.cnblogs.com/BlueSkyyj/p/9635841.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值