hive 的数据导入和导出
【导入】
1.load data [local]
-->本地,将数据文件copy到hdfs对应的目录,适合大部分场景使用
load data local inpath ' /opt/datas/emp.tx' into table emp;
load data local inpath '数据文件所在的目录(local_path)' into table tablename;
--->HDFS ,将数据文件move到hdfs对应的目录上,适合大数据集的存储
load data inpath ‘hdfs_path’into table tablename ;\
load data inpath ‘ /user/hive/warehouse/db_emp.db/student_b.txt’into table student_b ;
2.load data +overwrite 【覆盖数据】
load data [local] inpath 'path' overwrite into table tablename;
-->适合重复写入数据的表,一般指的是零时表,作为过渡使用
3.as select
create table tb(先建表) as select * from tb1;
-->适合数据查询结果的保存
4.insert方式
insert into select sql;---》追加
insert overwrite table select sql --》覆盖
测试:
create table tb like dept;(dept是库中已有的表,并且有数据)
加载数据 insert into table tb select * from dept;
5.location 方式
【导出】
1.insert overwrite [local] directory 'path' select sql ;
--->本地 insert overwrite local directory '/opt/datas/emp_01' select * from emp;
--->hdfs insert overwrite directory '/emp_02' select * from emp; (/ 是hdfs根目录)
2.bin/hdfs dfs -get xxx 下载数据文件(hive 客户端)
3.bin/hive -e 或者 -f >> 或者 > (>> 追加 > 覆盖)
4.sqoop 方式:import导入和export 导出
1.load data [local]
-->本地,将数据文件copy到hdfs对应的目录,适合大部分场景使用
load data local inpath ' /opt/datas/emp.tx' into table emp;
load data local inpath '数据文件所在的目录(local_path)' into table tablename;
--->HDFS ,将数据文件move到hdfs对应的目录上,适合大数据集的存储
load data inpath ‘hdfs_path’into table tablename ;\
load data inpath ‘ /user/hive/warehouse/db_emp.db/student_b.txt’into table student_b ;
2.load data +overwrite 【覆盖数据】
load data [local] inpath 'path' overwrite into table tablename;
-->适合重复写入数据的表,一般指的是零时表,作为过渡使用
3.as select
create table tb(先建表) as select * from tb1;
-->适合数据查询结果的保存
4.insert方式
insert into select sql;---》追加
insert overwrite table select sql --》覆盖
测试:
create table tb like dept;(dept是库中已有的表,并且有数据)
加载数据 insert into table tb select * from dept;
5.location 方式
【导出】
1.insert overwrite [local] directory 'path' select sql ;
--->本地 insert overwrite local directory '/opt/datas/emp_01' select * from emp;
--->hdfs insert overwrite directory '/emp_02' select * from emp; (/ 是hdfs根目录)
2.bin/hdfs dfs -get xxx 下载数据文件(hive 客户端)
3.bin/hive -e 或者 -f >> 或者 > (>> 追加 > 覆盖)
4.sqoop 方式:import导入和export 导出