从mysql增量导出到hive库
增量导入参数:--check-column Source column to check for incremental
--incremental Define an incremental import of type
--last-value Last imported value in the incremental
--columns 指定源表字段
--enclosed-by 行业分隔符
目前可以使用两种方式:
append模式
可以使用append 加 --where 来达到根据时间戳来增量更新。 sqoop import --connect jdbc:mysql://192.168.100.36:3306/test -username admin -password admin --table test_mysql_to_hive_mic --where "jap_date_time >20160101.100101 and jap_date_time <=20161127.100101" --hive-database mysql --hive-table test_mysql_to_hive --split-by des_mysql_id --hive-import --incremental append --check-column des_mysql_id --last-value 0 --enclosed-by "\t"
lastmodified模式
直接使用lastmodified来根据时间戳增量更新。 x sqoop import --connect jdbc:mysql://192.168.100.36:3306/test -username admin -password admin --table test_mysql_to_hive_mic --hive-database mysql --hive-table test_mysql_to_hive --split-by des_mysql_id --hive-import --incremental lastmodified --merge-key des_mysql_id --check-column jap_date_time --last-value "1980-11-28.11:30:00" --enclosed-by "\t"
问题记录
linux下执行Java调用略有不同,需要注意空格转义等问题,调用时可以指定运行环境,避免执行不生效。 xxxxxxxxxx Process process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmdA});
网上说sqoop默认行业分隔符为逗号,但是我使用sqoop导入到hive时,查看却是没有分隔符的。
所以,脚本和建hive脚本同时使用--enclosed-by "\t"比较靠谱
bin/sqoop import \
--connect jdbc:mysql://itcast01:3306/userdb \
--username root \
--password root123 \
--tabl