第1关:Sqoop 在HBase中导入

******第一关******

#开启服务

sh /data/workspace/myshixun/service.sh

#导入数据至MySQL

mysql -uroot -p123123 < /data/workspace/myshixun/step1/1.sql

#创建 HBase 表 tb_class

hbase shell

create 'tb_class','info'

exit

#Sqoop 将 MySQL 数据导入至 HBase 中

sqoop import -D sqoop.hbase.add.row.key=true --connect jdbc:mysql://127.0.0.1/school --username root --password 123123 --table tb_class --hbase-table tb_class --column-family info --hbase-row-key id -m 1

第2关:Sqoop 在HBase中导出

******第二关******

#启动服务(第一关启动了第二关可以不用启动)

sh /data/workspace/myshixun/service.sh

#启动 hbase 客户端

hbase shell

#插入数据

create 'book','info'

put 'book',1,'info:id',01

put 'book',1,'info:name','Hamlet'

put 'book',1,'info:author','William Shakespeare'

put 'book',1,'info:price',32

put 'book',2,'info:id',02

put 'book',2,'info:name','nahan'

put 'book',2,'info:author','luxun'

put 'book',2,'info:price',27

#退出hbase客户端

exit

#进入hive

hive

#创建 test 数据库

create database test;

#创建外部表 h_book

CREATE EXTERNAL TABLE test.h_book (key int,id int,name string,author string,price int)

STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'

WITH SERDEPROPERTIES (

"hbase.columns.mapping" =

":key,info:id, info:name,info:author,info:price"

)

TBLPROPERTIES( "hbase.table.name" = "book",

"hbase.mapred.output.outputtable" = "book");

#创建内部表 book

CREATE TABLE test.book(key int,id int,name string,author string,price int)row format delimited fields terminated by ',' stored as textfile;

#插入外部表的数据至内部表中

insert overwrite table test.book select * from test.h_book;

#退出 hive

exit;

#进入mysql客户端

mysql -uroot -p123123

#创建数据库test

create database test;

#创建表 book

create table test.book(rowkey int(11),id int(11),name varchar(20),author varchar(20),price int(11),primary key (id));

#退出客户端

exit

#sqoop导出数据至mysql中

sqoop export -connect jdbc:mysql://127.0.0.1:3306/test -username root -password 123123 -table book --fields-terminated-by ',' --export-dir /opt/hive/warehouse/test.db/book

相关阅读

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: