1:直接向表中插入数据
强烈不推荐使用
hive (myhive)> create table score3 like score;
hive (myhive)> insert into table score3 partition(month ='201807') values ('001','002','100');
2:通过load加载数据
语法
hive> load data [local] inpath 'dataPath' [overwrite] into table student [partition (partcol1=val1,…)];
通过load方式加载数据
hive (myhive)> load data local inpath '/install/hivedatas/score.csv' overwrite into table score partition(month='201806');
3:通过查询加载数据
通过查询方式加载数据
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...) [IF NOT EXISTS]] select_statement1 FROM from_statement;
INSERT INTO TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement;
例子
hive (myhive)> create table score5 like score;
hive (myhive)> insert overwrite table score5 partition(month = '201806') select s_id,c_id,s_score from score;
4:查询语句中创建表并加载数据
将查询的结果保存到一张表当中去
hive (myhive)> create table score6 as select * from score;
5:创建表时指定location
创建表,并指定在hdfs上的位置
hive (myhive)> create external table score7 (s_id string,c_id string,s_score int) row format delimited fields terminated by '\t' location '/myscore7';
上传数据到hdfs上,我们也可以直接在hive客户端下面通过dfs命令来进行操作hdfs的数据
hive (myhive)> dfs -mkdir -p /myscore7;
hive (myhive)> dfs -put /kkb/install/hivedatas/score.csv /myscore7;
查询数据
hive (myhive)> select * from score7;
6:export导出与import 导入 hive表数据
hive (myhive)> create table teacher2 like teacher;
-- 导出到hdfs路径
hive (myhive)> export table teacher to '/teacher';
hive (myhive)> import table teacher2 from '/teacher';