暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

sqoop与hbase导入导出数据

BigData社区 2019-08-21
296


mysql导入hbase可以直接通过sqoop进行 
hbase导出到mysql无法直接进行,需要经过hive的中间作用来完成 
hbase→hive外部表→hive内部表→sqoop导出→mysql


一.sqoop导入Hbase


    1.mysql创表

    mysql> create table test.smq_to_hbase select id,name,name grade from test.smq_mysql;
    mysql> update test.smq_to_hbase set grade = '1';
    mysql> Alter table test.smq_to_hbase add primary key(id);

        2.hbase创表

      hbase(main):008:0> create 'smq_hbase','info'

          3.sqoop导入hbase

        [root@master bin]# sqoop import --connect jdbc:mysql://192.168.220.20:3306/test --username root --password 123456 --table smq_to_hbase --hbase-table smq_hbase --column-family info --hbase-row-key id



        二.sqoop导出Hbase


        Hbase→hive外部表→hive内部表→通过sqoop→mysql

            1.mysql创建空表

          mysql> create table test.employee(rowkey int(11),id int(11),name varchar(20),primary key (id));

              2.hbase创建内部表

            hbase(main):001:0> create 'employee','info'
            hbase(main):002:0> put 'employee',1,'info:id',1
            hbase(main):003:0> put 'employee',1,'info:name','peter'
            hbase(main):004:0> put 'employee',2,'info:id',2
            hbase(main):005:0> put 'employee',2,'info:name','paul'

                3.hive创建外部表

              CREATE EXTERNAL TABLE test.h_employee (key int,id int,name string)
              STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
              WITH SERDEPROPERTIES (
              "hbase.columns.mapping" =
              ":key,info:id, info:name"
              )
              TBLPROPERTIES( "hbase.table.name" = "employee",
                  "hbase.mapred.output.outputtable" = "employee");

                  4.hive创建内部表

                hive> CREATE TABLE test.employee(key INT,id INT,name STRING);

                    5.hive外部表的数据导入内部表

                  hive> insert overwrite table test.employee select * from test.h_employee;

                      6.sqoop导出hive表至mysql中

                    [root@master bin]# sqoop export -connect jdbc:mysql://192.168.220.20:3306/test -username root -password 123456  -tablemployee -export-dir /user/hive/warehouse/test.db/employee --input-fields-terminated-by '\001' --input-null-string '\\N' --input-null-non-string '\\N';



                    以上就是今天的所有内容啦。希望能在你学习的路上帮到你,要是觉得还不错请识别以下二维码关注或转发吧,感谢支持!


                    如果喜欢小编的内容,可以关注"BigData社区",

                    加小编微信:876038581ljl



                    推荐阅读:

                    1. Hbase的完全分布式安装

                    2. Hbase的API(增删改查)

                    3. Hbase结构和基础操作

                    4. kafka优化总结(三)




                    文章转载自BigData社区,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                    评论