修炼离线:(六)hive通过sqoop同步数据到mysql

一:同步脚本。

#!/bin/sh

mysqlHost=$1
mysqlUserName=$2
mysqlUserPass=$3
mysqlDbName=$4
myqlTbName=$5
hiveDbName=$6
hiveTbName=$7
partFieldName=$8
inputDate=$9
updateFieldName=${10}

echo ${mysqlHost}
echo ${mysqlUserName}
echo ${mysqlUserPass}
echo ${mysqlDbName}
echo ${myqlTbName}
echo ${hiveDbName}
echo ${hiveTbName}
echo ${partFieldName}
echo ${inputDate}
echo ${updateFieldName}

sqoop export --connect jdbc:mysql://${mysqlHost}/${mysqlDbName} \
--username ${mysqlUserName} \
--password ${mysqlUserPass} \
--table ${myqlTbName} \
--hcatalog-database ${hiveDbName} \
--hcatalog-table ${hiveTbName} \
--hcatalog-partition-keys ${partFieldName}  \
--hcatalog-partition-values ${inputDate} \
--update-key ${updateFieldName} \
--update-mode allowinsert \
--m 1

二:同步命令。

sh hive_mysql.sh xx.xx.xx.xx root 123456 dongfeng bluetooth_device ods ods_dk_bluetooth_idk_bluetooth_device p_dt 2023-09-19 p_dt

你可能感兴趣的:(修炼篇,hive,sqoop,mysql)