hbase导出数据到mysql

原问地址:https://www.cnblogs.com/felixzh/p/11362183.html

环境:sqoop1.4.6+hadoop2.6+hbase1.1+mysql5.7 
说明: 
1.文中的导入导出的表结构借鉴了网上的某篇博客 
2.mysql导入hbase可以直接通过sqoop进行 
3.hbase导出到mysql无法直接进行,需要经过hive的中间作用来完成 
hbase→hive外部表→hive内部表→sqoop导出→mysql

一、Sqoop导入hbase
a) 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);

b) Hbase创建表

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

c) 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

a) Mysql创建空表

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

b) 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'

c) 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");

d) hive创建内部表

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

e) hive外部表的数据导入内部表中

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

f) sqoop导出hive表至mysql中

[root@master bin]# sqoop export -connect jdbc:mysql://192.168.220.20:3306/test -username root -password 123456 -tablemploye
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值