Sqoop使用

匿名 (未验证) 提交于 2019-12-02 23:55:01
导入:从其他数据源写入"hdfs"
导出:从"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 '|';

实现原理: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;

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;

导出整张数据表

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!