大数据-Hive 常用命令

2023-04-07编程技术278323

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表中
创建表时从别的表查到数据并插入的所创建的表中

大数据-Hive 常用命令的相关教程结束。

本文地址:https://www.ufcn.cn/tutorials/2423802.html

如非特殊说明,本站内容均来自于网友自主分享,概不代表本站观点,如有任何问题我们都将在收到反馈后的第一时间进行处理!