hive建立資料庫

2021-10-01 11:57:32 字數 2319 閱讀 4077

hive建立資料庫

create  database  if not exists  sip_data_drc  comment '測試資料庫'  location '/tmp/hive/root/' with dbproperties ('creater'='liuzd','date'='20191010');
if not exists:如果不存在則建立

comment:新增注釋

location:指定hdfs存放路徑

with dbproperties:新增自定義屬性

hive 啟動服務命令及連線
啟動元資料服務

./hive --service metastore &

啟動server

./hive --service hiveserver2 -hiveconf hive.server2.thrift.port=10000 &

連線hive服務

beeline -u "jdbc:hive2://主機名:埠/default;hive.server2.proxy.user=hive"

查詢資料庫資訊
desc database  extended sip_data_drc;
刪除資料庫
drop database sip_data_drc cascade;
資料庫切換
use sip_data_drc
常用資料型別
int:整型 

bigint:長整型

float:浮點型

double:雙精度

string:字串

建立hive表

外部表

create external table if not exists resource 

(id int comment '編號',name string comment '姓名')

comment '人員表'

stored as textfile

location '/user/hdfs/'

內部表
create table if not exists person 

(id int comment '編號',name string comment '姓名')

comment '人員表'

stored as textfile;

臨時表
create temporary table if not exists person_tmp 

(id int comment '編號',name string comment '姓名')

comment '人員臨時表'

stored as textfile

location '/user/hdfs/';

external:建立外部表的關鍵字,預設是內部表

comment:新增注釋,跟在字段後就是欄位的注釋,跟在表後就是表的注釋

row format delimited fields terminated by '\t':指定載入資料的列分隔符為製表符

location:指定表資料存放路徑

like方式建立表,複製表結構
create external table table_test1 like hive_table location '/user/hive/warehouse/test.db/emp';
刪除表
drop table [if exists] table_name [purge];
如果被刪除的表有檢視引用,在刪除時不會警告,需要手動檢查或重建檢視

如果指定了purge,刪除表時資料會從hdfs上完全清除,而不會轉入**站

insert方式插入資料(追加)

insert into new_table select * from hive_table;
insert方式插入資料(覆蓋)
insert overwrite  new_table select * from hive_table;
注:hive_table和new_table結構要一致,字段順序要一致。

載入hdfs檔案到hive

load data inpath '/user/hive/warehouse/ts_drc_catalog_resource_20191010.txt' overwrite into table table_resource;

Hive之資料庫建立 查詢 刪除

入門寫法 hive default create database test 注 這個資料庫的預設在hdfs上的儲存路徑是 user hive warehouse db 位置配置 hive.metastore.warehouse.dir 例如,user hive warehouse 所定義的目錄的子...

Hive建立 刪除 修改 使用資料庫

create database schema if not exists database name comment database comment location hdfs path with dbproperties property name property value,schema和d...

HIVE倉庫擴充套件 連線hive資料庫

一 命令列客戶端工具 hivecli cli是和hive互動的最簡單 最常用方式,你只需要在乙個具備完整hive環境下的shell終端中鍵入hive即可啟動服務。beeline beeline是hive新的命令列客戶端工具。hive客戶端工具後續將使用beeline 替代hivecli 並且後續版本...