Sqoop使用

说明

导入:从其他数据源写入"hdfs"
导出:从"hdfs"写入到其他存储设施
表名和字段不能有中文

MySQL –> HDFS

导入整个数据表 (默认使用MySQL的3306端口)

sqoop import --connect jdbc:mysql://172.16.1.150/mysql --username root --password 123456 --table zhilianjobs --target-dir /hive_table/zhilianjobs -m -1 --fields-terminated-by '|' --columns name,space,pay,skill;

导入查询结果

sqoop import --connect jdbc:mysql://172.16.1.150/mysql --username root --password 123456 --query 'select * from zhilianjobs WHERE $CONDITIONS' --target-dir /hive_table/zhilianjobs --delete-target-dir -m 1 --fields-terminated-by '|';

MySQL –> Hive

实现原理:https://www.cnblogs.com/xuyou551/p/7998846.html

导入整张数据表到hive

sqoop import --connect jdbc:mysql://172.16.1.150/mysql --username root --password 123456 --table zhilianjobs  --fields-terminated-by '|' --delete-target-dir -m 1  --hive-import --hive-database default --hive-table zljobsTest;

导入数据表的指定字段到hive

sqoop import --connect jdbc:mysql://172.16.1.150/mysql --username root --password 123456 --table zhilianjobs --columns 'name,space,pay,skill' --where '1=1'  --fields-terminated-by '|' --delete-target-dir -m 1  --hive-import --hive-database default --hive-table zljobs;

MySQL –> Hbase

sqoop import -D sqoop.hbase.add.row.key=true --connect jdbc:mysql://172.16.1.150/mysql --username root --password 123456 --table zhilianjobs --columns ID,NAME,SPACE,PAY,SKILL --hbase-create-table --hbase-table zljobstest --column-family data --hbase-row-key ID --where "ID>=0"  -m 1;

Hive –> MySQL

导出整张数据表

sqoop export --connect jdbc:mysql://172.16.1.150/mysql? useUnicode=true&characterEncoding=utf8 --username root --password 123456 --table zhilianjobsTest --export-dir /user/hive/warehouse/zljobstest  --fields-terminated-by '|';

导出相对于MySQL数据表新增的数据

sqoop export --connect jdbc:mysql://172.16.1.150:3306/testdb --username root --password 123456 --table test_table --fields-terminated-by ',' --update-key id --update-mode allowinsert --export-dir /user/hive/warehouse/wht_test1

导出相对于MySQL修改过的数据,不会导入新增的数据

sqoop export --connect jdbc:mysql://172.16.1.150:3306/wht --username root --password 123456 --table wht_test2 --fields-terminated-by ',' --update-key c_id --update-mode updateonly  --export-dir /user/hive/warehouse/wht_test1

HDFS –> MySQL

和Hive –> MySQL一样

转载于:https://www.cnblogs.com/studyNotesSL/p/11420176.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值