首先把修正后的脚本放出来,然后在说说踩得那些坑!
可以直接下滑到中间从看特别注意开始看。
sqoop export 脚本:
/home/huser/sqoop-1.4.7/bin/sqoop export --connect "jdbc:mysql://localhost9:3306/analysisuseUnicode=true&characterEncoding=
utf-8" \
--username mysql \
--password Pass2020 \
--table tmp_dws_visit_source \
--columns days,visitSourceType,visitSource \
--input-fields-terminated-by '^A' \
--input-lines-terminated-by '\n' \
--input-null-string '\\N' \
--input-null-non-string '\\N' \
--export-dir "hdfs://hadooprt:9000/user/hive/warehouse/rt1.db/dws_visit_source/everyday=2020-08-06/" \
-m 1;
mysql创建表脚本:
#!/bin/bash
everyday="2020-08-06"
sql=$(cat << !EOF
use database;
drop table dws_visit_source;
create table if not exists dws_visit_source(
days string,
visitSourceType string,
visitSource string
)
partitioned by (everyday string)
row format delimited
fields terminated by '^A'
lines terminated by '\n'
stored as textfile;
insert into table dws_visit_source partition(everyday='$everyday1')
select everyday,visitSourceType,visitSource
from cr_t_test08 where everyday='$everyday' group by visitSourceType,visitSource;
exit;
!EOF)
$HIVE_HOME/bin/hive -e "$sql"
exitCode=$?
if [ $exitCode -ne 0 ];then
echo "[ERROR] hive execute failed!" >> tmplog.txt
exit $exitCode
fi
mysql