sqoop从hbase导出数据到mysql

目前sqoop没有办法把数据直接从Hbase导出到mysql。必须要通过Hive建立2个表,一个外部表是基于这个Hbase表的,另一个是单纯的基于hdfs的hive原生表,然后把外部表的数据导入到原生表(临时),然后通过hive将临时表里面的数据导出到mysql

数据准备

mysql建立空表


?
1
2
3
4
5
6
CREATE TABLE `employee` (
   `rowkey` int (11) NOT NULL ,
   `id` int (11) NOT NULL ,
   ` name ` varchar (20) NOT NULL ,   
   PRIMARY KEY (`id`)   
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;



注意:因为大家习惯性的把hive表用于映射Hbase的rowkey的字段命名为key,所以在建立mysql的table的时候有可能也建立对应的key字段,但是key是mysql的保留字,会导致insert语句无法插入的问题 

Hbase建立employee表

建立employee表,并插入数据
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
hbase(main):005:0> create 'employee' , 'info'
0 row(s) in 0.4740 seconds
 
=> Hbase:: Table - employee
hbase(main):006:0> put 'employee' ,1, 'info:id' ,1
0 row(s) in 0.2080 seconds
 
hbase(main):008:0> scan 'employee'
ROW                                      COLUMN +CELL                                                                                                          
  1                                       column =info:id, timestamp =1417591291730, value=1                                                                     
1 row(s) in 0.0610 seconds
 
hbase(main):009:0> put 'employee' ,1, 'info:name' , 'peter'
0 row(s) in 0.0220 seconds
 
hbase(main):010:0> scan 'employee'
ROW                                      COLUMN +CELL                                                                                                          
  1                                       column =info:id, timestamp =1417591291730, value=1                                                                     
  1                                       column =info: name , timestamp =1417591321072, value=peter                                                               
1 row(s) in
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值