使用sqoop的update-only添加并补全mysql表指定字段
需求介绍
收到这样一个需求:200w数据的MySQL表中增加一个新的字段,并补全该字段的历史数据,该表的历史数据可以通过订单号从hive归档表中获取到,基于需求首先想到的就是sqoop能不能实现,答案当然可以
实现需求sqoop语句
sqoop export -Dmapreduce.job.name={JOB_NAME} --connect ‘jdbc:mysql://database-mysql.xxxxxx.com:3306/xxxxxbase’ --username ‘xxxx’ --password ‘xxxxxx’ --table xxx_statistics --export-dir ‘/data/xxxx/dev/xxxxx_yyk’ --input-fields-terminated-by ‘\001’ --input-null-non-string ‘\N’ --input-null-string ‘\N’ –update-key order_id –update-mode updateonly –columns order_id,member -m 10
语句关键点分析
1、--update-mode updateonly 指定更新模式为 仅仅更新
2、 --update-key order_id 指定更新字段 该字段必须为唯一键或是主键
3、--columns order_id,member 指定mysql 字段 对应的hdfs 字段的index
注意以上三个点就能做到 sqoop 更新指定字段