1.从外部文件系统向表中加载数据 load [overwrite] into
load data [local] inpath "" [overwrite] into table table_name [partition(col_name="")]
local:表示从本地加载数据到HIVE表,否则从HDFS加载
overwrite:表示覆盖表中已有数据,否则表示追加
(1)从本地上传数据到表格 load data local inpath "/opt/module/datas/student.txt" into table kg_risk_student; (2)从hdfs上传数据到表格 load data inpath "/student.txt" into table kg_risk_student;
2.通过查询语句向表中插入数据 insert overwrite/into
(1)基本插入数据 overwrite/into insert overwrite/into table bigdata17-user_parttion partition(userid=1) values("zhang","zhangshan"); (2)根据查询结果插入语句 insert overwrite/into table bigdata17-user_parttion partition(userid=1) select username ,fullname from bigdata17_user;
3.查询语句直接创建并加载数据 as
create table if not exists student2 as select * from student;
4.创建表时通过Location指定加载数据路径
(1)创建表,并指定hdfs路径 drop table if exists student; create table if not exists student( id int, name string, gender string) row format delimited fields terminated by "," lacation "/user/hive/warehouse/student" ; (2)数据上传到hdfs dfs -put /opt/module/datas/student.txt /user/hive/warehouse/student (3)查询数据 select * from student
5.import 导入到HIVE
import table student from "/user/hive/warehouse/export/student"