#!/bin/bash
if [ $1 ];
then
export hive_db_name=$1
else
echo “请指定要导出的源数据库”
exit 1
fi
if [ $2 ];
then
export hive_t_name=$2
else
echo “请指定要导出的源表名”
exit 1
fi
if [ $3 ];
then
export mysql_db_name=$3
else
echo “请指定目标数据库”
exit 1
fi
echo "这是一个通用的数据导出脚本...,手动创建目标表并保持和源表同名"
export_data() {
/root/module/sqoop/bin/sqoop export \
--connect "jdbc:mysql://192.168.0.201:3306/${mysql_db_name}?useUnicode=true&characterEncoding=utf-8" \
--username root \
--password ****** \
--table $1 \
--num-mappers 1 \
--export-dir /warehouse/$hive_db_name/ads/$1 \
--input-fields-terminated-by "\t" \
--update-mode allowinsert \
--update-key $2 \
--input-null-string '\\N' \
--input-null-non-string '\\N'
}
export_data "$hive_t_name" "dt"