Sqoop-从hive导出分区表到MySQL

经多次验证,发现并没有特殊的方法能够直接把多个分区一次性读入,并插入MySQL的方法,以后发现会在此添加。

Sqoop只提供了从MySQL导入到HIVE分区表的相关参数,反向并无特别参数。

从HIVE分区表导入到MySQL,需要依次导入每个分区的数据

sqoop export  

--connect jdbc:mysql://server74:3306/Server74  

--username root  

--password 123456  

--table dw_pvs_hour

--hive-partition-key datestr

--hive-partition-value ‘2017-11-05’

--export-dir /user/hive/warehouse/dw_pvs_hour/datestr=2017-11-15/ 

--input-fields-terminated-by '01'  

--input-lines-terminated-by ' '

 

根据官方文档的说法,---export-dir这个参数是必须的,指定hive表源文件路径后,sqoop回到路径下路径下的文件,文件不是路径否则报错。所以分区表需要单独指定每个分区的目录,分别导入。

The --export-dir argument and one of --table or --call are required. These specify the table to populate in the database (or the stored procedure to call), and the directory in HDFS that contains the source data.

原文地址:https://www.cnblogs.com/kouryoushine/p/7844352.html