数据库操作
创建数据库
create database if not exists hive;
查看存在的数据库
show databases;
查看以 "h" 开头的数据库
show databases like 'h.*' ;
#查看hive数据库位置等信息
describe databases;
删除不包含表的数据库
drop database if exists hive;
#删除数据库和它中的表
drop database if exists hive cascade;
切换到hive数据库
use hive;
内部表
create table if not exists table_test(id int ,name string,sex string) row format delimited fields terminated by "\t" lines terminated by "\n" stored as textfile;
外部表
hdfs dfs - mkdir / user / hive/ warehouse/ external
hdfs dfs - put data.txt / user / hive/ warehouse/ external
create table external table_external (name string,age int ) row format delimited fields terminated by "\t" location '/user/hive/warehouse/external' ;
分区表
创建分区表
create table tb_partition(id string, name string) PARTITIONED BY (month string) row format delimited fields terminated by '\t' ;
导入数据到分区表中
load data local inpath '/home/hadoop/files/nameinfo.txt' overwrite into table tb_partition partition (month = '201709' );
insert overwrite table tb_partition partition (month = '201707' ) select id, name from tmp_table;
hdfs dfs - mkdir / user / hive/ warehouse/ tb_partition/ month = 201710
hdfs dfs - put nameinfo.txt / user / hive/ warehouse/ tb_partition/ month = 201710
msck repair table tb_partition;
修改分区路径
alter table usr2 partition (city= ”beijing”,state= ”China”) set location '/usr/local/hive/warehouse/usr2/CH/beijing' ;
删除分区
alter table usr2 drop if exists partition (city= ”beijing”,state= ”China”)
分区表的其他操作:https://www.cnblogs.com/one--way/p/7550795.html
创建相同表结构的表
create table if not exists hive.usr1 like hive.usr;
查看表信息
show tables;
show tables in hive;
show tables 'u.*' ;
describe hive.usr;
desc hive.usr
表操作
alter table usr rename to custom;
alter table table_name change col1 col2 string;
alter table usr add columns(hobby string);
alter table usr replace columns(uname string);
drop table if exists usr1;
视图
create view view_name as select * from usr;
drop view if exists view_name;
查询
select name detail from where name like "%s数据%s";
select count (distinct uid) from bigdata_user;
导入数据
load data local inpath 'xiong.txt' into table xiong;
load data inpath '/home/xiong/add.txt' into table xiong;
执行脚本
shell使用Hive
hive - e 'desc cleantable;'
hive - S - e 'desc cleantable;' > desc.txt
hive - S - f / my.hql
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· Ollama系列05:Ollama API 使用指南
· 为什么AI教师难以实现