Hive的HiveQL

这篇博客详细讲解了Hive在Linux Shell中的参数使用,以及如何创建托管表、外部表和分区表。同时,探讨了Hive的数据导入导出方法,以及HiveQL如何与MapReduce配合执行。此外,还分享了一些常用的Hive SQL语句。
摘要由CSDN通过智能技术生成
# 启动Hive客户端
cd /opt/apache_hadoop/apache-hive-1.2.1
bin/hive


# 创建数据库
create database [if not exists] dbname;

# 显示数据库列表
show databases;

# 显示数据库表列表
show tables;

# 显示Hive的自带函数
show functions;
查看某函数信息
desc function func_name
例子:desc function sum;

# 删除数据库
drop database [if exists] dbname cascade;

# 选择数据库
use dbname;

# 创建数据库表
create table [if not exists] tbname(id int,name string)
row format delimited fields terminated by '\t';

# 读取数据写入表中

读取本地文件-->将本地文件数据复制到Hive表目录下
load data local inpath '/opt/data/student.txt' into table tbname;

读取HDFS目录下的文件-->将HDFS的文件移动到Hive表目录下
load data inpath '/data/student.txt' into table tbname;

# 查询表数据
select * from tbname
select * from tbname where 条件表达式

# 查询表结构
desc tbname;
desc formatted tbname;

# 删除表,注意:删除表是把表的元数据信息删除,同时HDFS上表目录和目录下的数据一起删除
drop table [if exists] tbname;

# 清空表数据,只删除表内数据,表还在,表的元数据信息不会删除。
truncate table tbname;

# 修改表名
alter table tbname rename to new_tbname;

# 表内添加列 
alter table tbname add columns(col,col_type,...);
例子:alter table tbname add columns(addr string, phone int);

# 修改表内列名及类型
alter table tbname change col_name new_col_name new_col_type;

# 替换列,注意:列不能删除,但可以修改或替换,会删除原来的所有列,新增替换的列。
alter table tbname replace columns(col col_type,...)

 

Hive的Linux Shell参数使用讲解

[root@aibigdata apache-hive-1.2.1]# bin/hive -help
usage: hive
 -d,--define <key=value>          Variable subsitution to apply to hive
                                  commands. e.g. -d A=B or --define A=B
    --database <databasename>     Specify the database to use
 -e <quoted-query-string>         SQL from command line
 -f <filename>                    SQL from files
 -H,--help                        Print help information
    --hiveconf <property=value>   Use value for given property
    --hivevar <key=value>         Variable subsitution to apply to hive
                                  commands. e.g. --hivevar A=B
 -i <filename>                    Initialization SQL file
 -S,--silent                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值