大数据全系列 教程
1869个小节阅读:467.9k
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
使用Sqoop抽取mysql数据到ODS层
将ycak.user_wechat_baseinfo
数据导入到ODS层TO_YCAK_USR_D
表中,对应的sqoop脚本 ods_mysqltohive_to_ycak_usr_d.sh
xxxxxxxxxx
[root@node3 ~]# cd music/sqoop/
[root@node3 sqoop]# vim ods_mysqltohive_to_ycak_usr_d.sh
内容如下:
xxxxxxxxxx
sqoop import \
--connect jdbc:mysql://node1:3306/ycak?dontTrackOpenResources=true\&defaultFetchSize=10000\&useCursorFetch=true\&useUnicode=yes\&characterEncoding=utf8 \
--username root \
--password 123456 \
--table user_wechat_baseinfo \
--target-dir /user/hive_remote/warehouse/data/user/TO_YCAK_USR_D/ \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
将ycak.user_alipay_baseinfo
数据导入到ODS层TO_YCAK_USR_ALI_D
表中,对应的sqoop脚本 ods_mysqltohive_to_ycak_usr_ali_d.sh
xxxxxxxxxx
[root@node3 sqoop]# vim ods_mysqltohive_to_ycak_usr_ali_d.sh
内容如下:
xxxxxxxxxx
sqoop import \
--connect jdbc:mysql://node1:3306/ycak?dontTrackOpenResources=true\&defaultFetchSize=10000\&useCursorFetch=true\&useUnicode=yes\&characterEncoding=utf8 \
--username root \
--password 123456 \
--table user_alipay_baseinfo \
--target-dir /user/hive_remote/warehouse/data/user/TO_YCAK_USR_ALI_D/ \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
将ycak.user_qq_baseinfo
数据导入到ODS层TO_YCAK_USR_QQ_D
表中,对应的sqoop脚本 ods_mysqltohive_to_ycak_usr_qq_d.sh
xxxxxxxxxx
[root@node3 sqoop]# vim ods_mysqltohive_to_ycak_usr_qq_d.sh
内容如下:
xxxxxxxxxx
sqoop import \
--connect jdbc:mysql://node1:3306/ycak?dontTrackOpenResources=true\&defaultFetchSize=10000\&useCursorFetch=true\&useUnicode=yes\&characterEncoding=utf8 \
--username root \
--password 123456 \
--table user_qq_baseinfo \
--target-dir /user/hive_remote/warehouse/data/user/TO_YCAK_USR_QQ_D/ \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
将ycak.user_app_baseinfo
数据导入到ODS层TO_YCAK_USR_APP_D
表中,对应的sqoop脚本 ods_mysqltohive_to_ycak_usr_app_d.sh
xxxxxxxxxx
vim ods_mysqltohive_to_ycak_usr_app_d.sh
内容如下:
xxxxxxxxxx
sqoop import \
--connect jdbc:mysql://node1:3306/ycak?dontTrackOpenResources=true\&defaultFetchSize=10000\&useCursorFetch=true\&useUnicode=yes\&characterEncoding=utf8 \
--username root \
--password 123456 \
--table user_app_baseinfo \
--target-dir /user/hive_remote/warehouse/data/user/TO_YCAK_USR_APP_D/ \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
将ycak.user_login_info
数据导入到ODS层TO_YCAK_USR_LOGIN_D
表中,这里是每天增量导入,对应的sqoop脚本ods_mysqltohive_to_ycak_usr_login_d.sh
xxxxxxxxxx
vim ods_mysqltohive_to_ycak_usr_login_d.sh
内容如下:
x
currentDate=`date -d today +"%Y%m%d"`
if [ x"$1" = x ]; then
echo "====没有导入数据的日期,输入日期===="
exit
else
echo "====使用导入数据的日期 ===="
currentDate=$1
fi
echo "日期为 : $currentDate"
#查询hive ODS层表 TO_YCAK_USR_LOGIN_D 中目前存在的最大的ID
maxid=`hive -e "select max(id) from baizhan_music.TO_YCAK_USR_LOGIN_D"`
echo "Hive ODS层表 TO_YCAK_USR_LOGIN_D 最大的ID是$maxid"
if [ x"$maxid" = xNULL ]; then
echo "maxid is NULL 重置为0"
maxid=0
fi
#sqoop 导入数据:
sqoop import \
--connect jdbc:mysql://node1:3306/ycak?dontTrackOpenResources=true\&defaultFetchSize=10000\&useCursorFetch=true\&useUnicode=yes\&characterEncoding=utf8 \
--username root \
--password 123456 \
--table user_login_info \
--target-dir /user/hive_remote/warehouse/data/user/TO_YCAK_USR_LOGIN_D/data_dt=${currentDate} \
--num-mappers 1 \
--fields-terminated-by '\t' \
--incremental append \
--check-column id \
--last-value $maxid
#更新Hive 分区
hive -e "alter table baizhan_music.TO_YCAK_USR_LOGIN_D add partition(data_dt=${currentDate});"