修炼离线:(二)sqoop插入hbase 脚本(增量)

一:mysql创建表,插入数据。

二:hbase创建表。

habse shell
create 'aa'(表名),'cf'(列族)

三:mysql_hbase脚本。

#!/bin/sh

mysqlHost=$1
mysqlUserName=$2
mysqlUserPass=$3
mysqlDbName=$4
myqlTbName=$5
hbaseTbName=$6
hbaseTbRowkey=$7
hbaseTbRowfamily=$8
mysqlUpdateField=$9
lastMonthDealDate=${10}
p_dt=${11}

echo ${mysqlHost}
echo ${mysqlUserName}
echo ${mysqlUserPass}
echo ${mysqlDbName}
echo ${myqlTbName}
echo ${hbaseTbName}
echo ${hbaseTbRowkey}
echo ${hbaseTbRowfamily}
echo ${mysqlUpdateField}
echo ${lastMonthDealDate}
echo ${p_dt}


sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
"-Dsqoop.hbase.add.row.key=true"  \
--connect jdbc:mysql://${mysqlHost}/${mysqlDbName} \
--username ${mysqlUserName} \
--password ${mysqlUserPass} \
--table ${myqlTbName} \
--hbase-table ${hbaseTbName} \
--hbase-row-key ${hbaseTbRowkey} \
--column-family ${hbaseTbRowfamily} \
--where "date_format(${mysqlUpdateField},'%Y-%m-%d') between '${lastMonthDealDate}' and '${p_dt}'"

#--num-mappers 16

四:shell脚本。

sh mysql_hbase.sh 27.155.84.54 root 123456 aaa(mysql库名) bbb(mysql表名)  MANUFACTURER,BLE_ID(hbase的rowkey) cf(hbase列族) edit_time(mysql更新字段) 2021-09-01(开始日期) 2023-09-19(结束日期)

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