1. 向表中装载数据(Load)

load data [local] inpath '路径' [overwrite] into table 表名 [partition (分区字段=值,…)];

overwrite:表示覆盖表中已有数据,否则表示追加

如:

  从本地文件系统加载数据到hive表

load data local inpath '/home/hdfs/data/test.txt' into table test;

在这里插入图片描述
  从hdfs文件系统加载数据覆盖hive表

hive (default)> dfs -put /home/hdfs/data/test.txt /wcinput;
hive (default)> load data inpath '/wcinput/test.txt' overwrite into table test;

在这里插入图片描述


2. 通过查询语句向表中插入数据

insert into:以追加数据的方式插入到表或分区,原有数据不会删除

 INSERT INTO TABLE tablename1 [PARTITION(partcol1=val1, partcol2=val2 ...)]  select_statement1 FROM from_statement;

insert overwrite:覆盖表中已存在的数据

INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) ]  select_statement1 FROM from_statement;

3. 创建表时加载数据

(1)创建表时使用查询语句as select

create table if not exists 表名 as select_statement1 FROM from_statement;

(2)创建表时通过location指定加载数据路径


4. Import数据到指定Hive表中

先用export导出后,再将数据导入(export和import主要用于两个Hadoop平台集群之间Hive表迁移)

import table 表名 from '路径';

如:
从a集群中导出hive表数据:

export table default.student to '/wcinput/export';

在这里插入图片描述

向b集群中导入数据到hive表:

import table student from '/wcinput/export' ;

在这里插入图片描述


5. sqoop导入数据

Sqoop User Guide


Logo

大数据从业者之家,一起探索大数据的无限可能!

更多推荐