【sqoop】将mysql表同步到hive分区表中

 以下文章是mysql表导入到hiveTEXTfile存储格式的分区表中

mysql表导入到hiveORC存储格式的分区表  请点此跳转

 一、从mysql导入到hive表分区数据的hdfs的存储位置==(mysql-->>hdfs)

sqoop import \
--connect jdbc:mysql://IP:3306/DATABASE \
--username USENAME--password PWD \
--fields-terminated-by ',' \
--m 1 \
--query "select * from TABLE where COLUMN='VALUE' and \$CONDITIONS" \
--target-dir /user/hive/warehouse/DATABASE.db/TABLE/PARTITION_NAME=PARTITION_VALUE/ \
--delete-target-dir 

大写的地方需要自行修改

where子句的  and \$CONDITIONS   不要修改,必须加

 二、mysql-->>hive分区表(hive表不存在会自动创建)

sqoop import \
--connect jdbc:mysql://IP:3306/DB\
--username root --password PWD \
--query "select * from tab_task where task_createTime='2020-12-30' and \$CONDITIONS" \
--fields-terminated-by ',' \
--delete-target-dir \
--hive-import \
--m 1 \
--hive-partition-key dt \
--hive-partition-value 2020-12-30 \
--hive-database DB\
--hive-table tab_task \
--target-dir /user/hive/warehouse/DB.db/tab_task/dt=2020-12-30/ \
--delete-target-dir \
--direct

 如果分区字段task_createTime不是yyyy-MM-dd格式,可以用  date_format(${task_createTime},'%Y-%m-%d')

  1. 同步分区表要指定query
  2. query 最后要加and \$CONDITIONS

猜你喜欢

转载自blog.csdn.net/qq_44065303/article/details/112916572