zoukankan      html  css  js  c++  java
  • 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

     
  • 相关阅读:
    汇编语言 第二单元 整理
    iOS10推送必看UNNotificationServiceExtension
    RSA加,解密
    添加购物车动画
    长按移动cell
    http live streming
    修改工程
    searbar
    tableView 编辑模式
    iOS 3D touch
  • 原文地址:https://www.cnblogs.com/zy900406/p/6233769.html
Copyright © 2011-2022 走看看