mysql export import_HBase数据导入导出(export import)

1.export

1> 执行导出命令

可使用-D命令自定义参数,此处限定表名、列族、开始结束RowKey、以及导出到HDFS的目录

hbase org.apache.hadoop.hbase.mapreduce.Export -D hbase.mapreduce.scan.column.family=0 -D hbase.mapreduce.scan.row.start=aaaaaaaaaaaaaaaaaaa00010078 -D hbase.mapreduce.scan.row.stop=jjjjjjjjjjjjjjjjjjj00010078 TESTA /tmp/hbase_export

可选的-D参数配置项

Usage: Export [-D ]* [ [ []] [^[regex pattern] or [Prefix] to filter]]

Note: -D properties will be applied to the conf used.

For example:

-D mapred.output.compress=true

-D mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec

-D mapred.output.compression.type=BLOCK

Additionally, the following SCAN properties can be specified

to control/limit what is exported..

-D hbase.mapreduce.scan.column.family=

-D hbase.mapreduce.include.deleted.rows=true

For performance consider the following properties:

-Dhbase.client.scanner.caching=100

-Dmapred.map.tasks.speculative.execution=false

-Dmapred.reduce.tasks.speculative.execution=false

For tables with very wide rows consider setting the batch size as below:

-Dhbase.export.scanner.batch=10

2> MR执行导出

331cb0b6fa5272e4c0bd5d811c754a31.png

3> 查看HDFS

6e0692cff778b08d7a75371f75db0e55.png

2.import

1> 预先建表

在hbase中预先建立一个名称为TESTX的表,其包含一个名称为0的列族。若表事先不存在将报错

create 'TESTX','0'

aaec6f28baeeadb281a68fac4b8304a6.png

2> 运行导入命令

可使用-D命令自定义参数,此处不多做限制

hbase org.apache.hadoop.hbase.mapreduce.Import TESTX hdfs://cdh01/tmp/hbase_export/

可选的-D参数配置项

Usage: Import [options]

By default Import will load data directly into HBase. To instead generate

HFiles of data to prepare for a bulk data load, pass the option:

-Dimport.bulk.output=/path/for/output

To apply a generic org.apache.hadoop.hbase.filter.Filter to the input, use

-Dimport.filter.class=

-Dimport.filter.args=

NOTE: The filter will be applied BEFORE doing key renames via the HBASE_IMPORTER_RENAME_CFS property. Futher, filters will only use the Filter#filterRowKey(byte[] buffer, int offset, int length) method to identify whether the current row needs to be ignored completely for processing and Filter#filterKeyValue(KeyValue) method to determine if the KeyValue should be added; Filter.ReturnCode#INCLUDE and #INCLUDE_AND_NEXT_COL will be considered as including the KeyValue.

For performance consider the following options:

-Dmapred.map.tasks.speculative.execution=false

-Dmapred.reduce.tasks.speculative.execution=false

-Dimport.wal.durability=

3> MR执行导入

9dc782a9bf64f1d34db04513daf0293d.png

4> HBase查看导入数据

b4bfbdaf4baa2d7640291c99f16fdbb6.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用Sqoop来将HBase数据导入MySQL中,Sqoop是一个用于在Apache Hadoop和结构化数据存储(如Apache HBase和Apache Hive)之间传输数据的工具。以下是一些步骤: 1. 确保你已经安装了Sqoop,并且已经配置好了HBaseMySQL的连接。 2. 创建一个HBase表并将数据存储在其中。 3. 将HBase表中的数据导出到一个文件中,可以使用以下命令: ``` $ hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir> <scan> ``` 其中\<tablename>是你要导出的表的名称,\<outputdir>是输出文件的目录,\<scan>是一个扫描器配置字符串,用于指定要导出数据范围。 4. 现在你有了一个包含HBase数据的文件,你可以使用Sqoop将其导入MySQL中。以下是一个示例命令: ``` $ sqoop import --connect jdbc:mysql://<mysql-hostname>/<database> --username <username> --password <password> --table <tablename> --m 1 --fields-terminated-by '\t' --lines-terminated-by '\n' --null-string '\\N' --null-non-string '\\N' --input-fields-terminated-by '\t' --input-lines-terminated-by '\n' --input-null-string '\\N' --input-null-non-string '\\N' --target-dir <inputdir> ``` 其中\<mysql-hostname>是你的MySQL主机名,\<database>是你要导入数据数据库名称,\<username>和\<password>是你的MySQL用户名和密码,\<tablename>是你要导入数据的表的名称,\<inputdir>是包含你想要导入数据的目录。 请注意,这个命令使用了很多参数来指定输入和输出文件的格式,包括字段分隔符、行分隔符、空值字符串和空值非字符串。 5. 运行Sqoop命令后,数据将被导入MySQL中。你可以使用MySQL客户端验证导入数据是否正确。 希望这些步骤对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值