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

被折叠的 条评论
为什么被折叠?



