一.数据库操作
1.创建数据库
create database financials;
2.创建数据库,避免抛出错误信息
create database if not exists financials;
3.查看hive中包含的数据库
show databases;
4.显示当前所在数据库
use financials ;
5.删除空数据库
drop database if exists financials;
6.删除有表格的数据库
drop database if exists financials cascade;
7.修改数据库
alter database financials set dbproperties (`edited-by`=`job dba`);
二. 创建表
1.创建内部表
CREATE TABLE if not exists financials.employees1(
name STRING COMMENT 'Empolyee name',
salary FLOAT COMMENT 'Empolyee salary',
subordinates ARRAY<STRING> COMMENT 'Names of subordinates',
duduction MAP<STRING,FLOAT>
COMMENT 'Keys are deductions names,vlaues are percentages',
address STRUCT<street:STRING,city:STRING,state:STRING,zip:INT>
COMMENT 'Home address')
COMMENT 'Description ofthe table'
LOCATION '/user/hive/warehouse/financials.db/employees'
TBLPROPERTIES('creator'='li','created_at'='2014-1-23 10:00:00');
2.创建外部表
CREATE EXTERNAL TABLE financials.employees2(
ts String,
uid String,
keyword String,
rank int,
order int,
url String)
comment 'this
ts String,
uid String,
keyword String,
rank int,
order int,
url String)
comment 'this

本文详细介绍了Hive中的数据库操作,包括创建内部表、外部表和分区表,并展示了如何加载数据、创建分桶表以及删除表的操作。强调了分区和分桶对于查询效率的提升,以及如何通过Hadoop回收站恢复误删数据。
最低0.47元/天 解锁文章
714

被折叠的 条评论
为什么被折叠?



