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