Sqoop 数据导入导出

导入 MySQL 数据到 HDFS

1.普通导入

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--table help_keyword \
-m 1

2.指定分隔符和导入路径

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--table help_keyword \
--target-dir /user/centos/my_help_keyword \
--fields-terminated-by '\t' \
-m 1

3.导入 where 条件数据

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--where "name='DATE' " \
--table help_keyword \
--target-dir /user/centos/my_help_keyword01 \
-m 1

4.导入 Query 结果数据

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--target-dir /user/centos/my_help_keyword02 \
--query 'select help_keyword_id,name from help_keyword WHERE name = "STRING" and
$CONDITIONS' \
--split-by help_keyword_id \
--fields-terminated-by '\t' \
-m 1
sqoop import \
--connect jdbc:mysql://hadoop02:3306/mysql \
--username root \
--password root \
--target-dir /user/hadoop/myimport22 \
--query "select help_keyword_id,name from help_keyword WHERE name = 'STRING' and
\$CONDITIONS" \
--split-by help_keyword_id \
--fields-terminated-by '\t' \
-m 1

导入 MySQL 到 HIVE

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--table help_relation \
--hive-import \
-m 1
sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password root \
--table help_keyword01 \
--fields-terminated-by "\t" \
--lines-terminated-by "\n" \
--hive-import \
--hive-overwrite \
--create-hive-table \
--hive-table mydb_test.new_help_keyword \
--delete-target-dir

增量导入

sqoop import \
--connect jdbc:mysql://hadoop02:3306/mysql \
--username root \
--password root \
--table help_keyword \
--target-dir /user/hadoop/myimport3 \
--incremental append \
--check-column help_keyword_id \
--last-value 500 \
-m 1

导入 MySQL 数据到 HBase

sqoop import \
--connect jdbc:mysql://localhost:3306/mysql \
--username root \
--password 123456 \
--table help_keyword \
--hbase-table new_help_keyword \
--column-family person \
--hbase-row-key help_keyword_id

导出 HDFS 数据到 MySQL

第一步,先看需要导出到 mysql 的数据:

第二步,需要首先在 mysql 数据库中新建表:

create database sqoopdb default character set utf8 COLLATE utf8_general_ci;
use sqoopdb;
CREATE TABLE sqoopstudent (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(20),
sex VARCHAR(20),
age INT,
department VARCHAR(20)
);

第三步,执行导出:

sqoop export \
--connect jdbc:mysql://localhost:3306/sqoopdb \
--username root \
--password 123456 \
--table sqoopstudent \
--export-dir /sqoopdata \
--fields-terminated-by ','

导出 HIVE 数据到 到 MySQL

sqoop export \
--connect jdbc:mysql://localhost:3306/sqoopdb \
--username root \
--password 123456 \
--table uv_info \
--export-dir /user/hive/warehouse/uv/dt=2011-08-03 \
--input-fields-terminated-by '\t'

导出 HBase 数据到 MySQL

一般采用如下 3 种方法:
1、将 Hbase 数据,扁平化成 HDFS 文件,然后再由 sqoop 导入
2、将 Hbase 数据导入 Hive 表中,然后再导入 mysql
3、直接使用 Hbase 的 JavaAPI 读取表数据,直接向 mysql 导入,不需要使用 sqoop
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值