一:mysql创建表,插入数据。
二:hbase创建表。
sql
habse shell
create 'aa'(表名),'cf'(列族)
三:mysql_hbase脚本。
sql
#!/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脚本。
sql
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(结束日期)