sqoop全增量导出到mysql

本文介绍了如何使用HQL和SQOOP进行全量及增量数据导出到MySQL的过程。全量导出通过HQL插入数据到目录,然后用SQOOP将目录数据导出到MySQL。增量导出分为insert模式和update模式,需在HQL中添加适当条件,并配置SQOOP的update-key和update-mode。注意,MySQL表需设置主键,且Hive的存储格式会影响导出方式。

全量导出
HQL示例:insert overwrite directory ‘/user/root/export/test’ row format delimited fields terminated by ‘,’ STORED AS textfile select F1,F2,F3 from ;

SQOOP脚本:sqoop export --connect jdbc:mysql://localhost:3306/wht --username root --password cloudera --table --fields-terminated-by ‘,’ --columns F1,F2,F3 --export-dir /user/root/export/test

增量导出(insert模式)
HQL示例:insert overwrite directory ‘/user/root/export/test’ row format delimited fields terminated by ‘,’ STORED AS textfile select F1,F2,F3 from where ;

SQOOP脚本:sqoop export --connect jdbc:mysql://47.99.89.210:3306/phpmanager --username datamanager --password 4duL%*iALC --table t_stock_equipment1 --fields-terminated-by ‘\001’ --update-key hp_stat_date --update-mode allowinsert --export-dir /user/hive/warehouse/cdm.db/t_stock_equipment1

更新导出(update模式)
HQL示例:insert overwrite directory ‘/user/root/export/test’ row format delimited fields terminated by ‘,’ STORED AS textfile select F1,F2,F3 from where ;

SQOOP脚本:sqoop export --connect jdbc:mysql://localhost:3306/wht --username root --password cloudera --table --fields-terminated-by ‘,’ --columns F1,F2,F3 --update-key F4 --update-mode updateonly --export-dir /user/root/export/test

注意事项:
增量导出到mysql时候,hive要根据不同的存储格式来进行设置,mysql表必须设置主键,否则增量会无效
hive
text格式:
sqoop export --connect jdbc:mysql://197.0.0.1:3306/tg --username tgg --password 4duL%*iALC --table t_stock --fields-terminated-by ‘\001’ --export-dir /user/hive/warehouse/cdm.db/t_stock --update-key hp_stat_date --update-mode allowinsert

parquet格式存储:
sqoop export --connect jdbc:mysql://197.1.0.1:3306/tg–username tgg --password 4duL%*iALC --table t_stock --input-fields-terminated-by ‘\001’ --update-key hp_stat_date --update-mode allowinsert --hcatalog-database cdm --hcatalog-table t_stock --num-mappers 1

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值