Hive 外部表和內部表

2021-10-01 06:31:00 字數 1400 閱讀 3574

外部表說明:

外部表因為是指定其他的hdfs路徑的資料載入到表當中來,所以hive表會認為自己不完全獨佔這份資料,所以刪除hive表的時候,資料仍然存放在hdfs當中,不會刪掉

管理表和外部表的使用場景:

操作案例

分別建立老師與學生表外部表,並向表中載入資料

建立老師表:

create external table techer (t_id string,t_name string) row format delimited fields terminated by '\t';
建立學生表:

從本地檔案系統向表中載入資料

load data local inpath '/export/servers/hivedatas/student.csv' into table student;
載入資料並覆蓋已有資料

load data local inpath '/export/servers/hivedatas/student.csv' overwrite  into table student;
從hdfs檔案系統向表中載入資料(需要提前將資料上傳到hdfs檔案系統,其實就是乙個移動檔案的操作)

cd /export/servers/hivedatas

hdfs dfs -mkdir -p /hivedatas

hdfs dfs -put techer.csv /hivedatas/

load data inpath '/hivedatas/techer.csv' into table techer;

如果刪掉techer表,hdfs的資料仍然存在,並且重新建立表之後,表中就直接存在資料了,因為我們的techer表使用的是外部表,drop table之後,表當中的資料依然保留在hdfs上面了

hive外部表和內部表

1.內部表指hive建立並通過load data inpath進資料庫的表,這種表可以理解為資料和表結構都儲存在一起的資料表。當你通過drop table table name 刪除元資料中表結構的同時,表中的資料也同樣會從hdfs中被刪除。sql view plain copy create ta...

Hive內部表和外部表

總結一下hive的內部表和外部表以及兩者的區別。平時建立的普通表為內部表 create table test internal id string comment id name string comment 名字 comment 測試內部表 row format delimited fields ...

Hive 內部表和外部表

針對於hive 的 建庫建表操作建庫 內部表 也叫管理表和臨時表 外部表表的操作 建庫 建立名為 test 的資料庫 僅當不存在是才建立 新增備註資訊 test database create database if not exists test comment this is a databas...