首页 > 代码库 > mysql数据导入到hbase
mysql数据导入到hbase
思路:读取到一个数据库里所有的表名,然后通过sqoop循环导入到hbase
实现过程中发现 不会写shell是个硬伤
最后只能分两步进行操作
1.sel_tabs.sh
/usr/bin/mysql -hIp地址 -u用户名 -p密码 -D数据库名<<EOF
use
select table_name from information_schema.tables where table_schema=‘数据库名‘ and table_type=‘base table‘;
EOF
运行 bash sel_tabs.sh>tbsnam.dat
将结果写入tbsname.dat
2.readdat.sh
#!/bin/sh
cat tbsnam.dat |while read LINE
do
echo $LINE
if [ "$LINE" = "table_name" ]; then
echo "table_name test"
else
echo $LINE
str="/opt/dtma/sqoop/bin/sqoop import --connect jdbc:mysql://Ip地址:端口号/数据库名称 --username ‘用户名‘ --password ‘密码‘ --table AA --hbase-table AA --column-family f1 --hbase-row-key id --hbase-create-table --m 1 --incremental append --check-column ‘id‘ --last-value 0"
strend=${str//"AA"/$LINE}
echo $strend
$strend
fi
done
str是sqoop 增量导入单个表的 语句
上面sql语句查询结果 第一行出现 table_name,所以把table_name 剔除掉
最后运行
bash readdat.sh
mysql数据导入到hbase
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。