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

     
  • 相关阅读:
    两个有序数组,找第k小的数//未完
    top详解--查看cpu及内存使用情况
    查看IO情况
    hadoop常用的调优参数
    zookeeper 的 javaAPI
    MapReduce优化
    mySQL索引数据数据结构 B+ 树
    P2670 [NOIP2015 普及组] 扫雷游戏
    P1887 乘积最大3
    1299. 五指山
  • 原文地址:https://www.cnblogs.com/zy900406/p/6233769.html
Copyright © 2011-2022 走看看