hive内部表和外部表的区别简解

本文介绍了Hive中内部表和外部表的区别及创建过程。内部表的数据存储位置由Hive自身管理,删除表时会一同删除数据;而外部表只记录数据的位置,删除表时不会删除实际数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 内部表 :

    创建表:

hive> create table wyp(id int,

name string,
age int,
tele string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘\t’
STORED AS TEXTFILE;
OK
Time taken: 0.759 seconds
导入表:
做了以下几个步骤:
1.将本地的文件导入HDFS
2.将HDFS文件导入HVIE储存表的位置:/user/hive/warehouse/wyp(此路径是${HIVE_HOME}/conf/hive-site.xml配置文件的hive.metastore.warehouse.dir属性指向的路径),并以表明创建一个文件夹,存放次表的数据

hive> load data local inpath ‘/home/wyp/data/wyp.txt’ into table wyp;
Copying data from file:/home/wyp/data/wyp.txt
Copying file: file:/home/hdfs/wyp.txt
Loading data to table default.wyp
Table default.wyp stats: [num_partitions: 0, num_files: 1,
num_rows: 0, total_size: 67, raw_data_size: 0]
OK
Time taken: 3.289 seconds
hive> select * from wyp;
OK
1 wyp 25 13188888888888
2 test 30 13888888888888
3 zs 34 899314121
Time taken: 0.41 seconds, Fetched: 3 row(s)

2.外部表:

创建可以指定hive表存放的位置 > location ‘/home/wyp/external’;

hive> create external table exter_table(

id int,
name string,
age int,
tel string)
location ‘/home/wyp/external’;
OK
Time taken: 0.098 seconds

删除的时候,内部表 将文件移动到hdfs://mycluster/user/hdfs/.Trash/Current

hive> drop table wyp;
Moved: ‘hdfs://mycluster/user/hive/warehouse/wyp’ to
trash at: hdfs://mycluster/user/hdfs/.Trash/Current
OK
Time taken: 2.503 seconds

外部表只是删除元数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值