【知识分享】Sqoop通用参数&命令说明

友情链接:


① 通用参数说明

–username 源数据库名称
–password 密码
–connect 数据库JDBC连接串
–query SQL语句,其中 where $CONDITIONS 是固定写法
–target-dir 写入HDFS目录 后面跟的HDFS目录需要确认用户有写权限
-m -m 4 map个数,抽数的线程数,默认为4 当-m大于1时,需要指定–split-by 字段
–split-by --split-by id 数据划分列,默认为主键
–fetch-size --fetch-size 单次去多少条记录 一般取1000 可以不用
–null-string --null-string ‘\N’ string类型的空值
–null-non-string --null-non-string ‘\N’ 非string类型的空值
–delete-target-dir --delete-target-dir 导入数据前,清空hdfs目录
–field-terminated-by --field-terminated-by ‘\01’ 列分隔符
–hive-drop-import-delims 去除^A \n \r 等特殊字符
–append --append 是否设置为追加增量的方式导入,sqoop将把数据先导入到一个临时目录中,然后重新给文件命名到一个正式的目录中,以避免和该目录中已存在的文件重名。
-z -z,–compress 压缩格式,默认为gzip


② 简易命令:

#列出源数据库的数据库列表:
sqoop list-databases --username root --password 111111 --connect jdbc:mysql://192.168.164.25:3306/

#列出test数据库中所有的表:
sqoop list-tables --username root --password 111111 --connect jdbc:mysql://192.168.164.25:3306/test

#把数据从test数据库下的表person_all --table 模式 Sqoop 抽取到HDFS目录 /user/root/person_all
sqoop import --username root --password 111111 --connect jdbc:mysql://192.168.164.25:3306/test --table person_all --target-dir /user/root/person_all -m 1 -fields-terminated-by “\01” --null-string ‘\N’ --null-non-string ‘\N’ --hive-drop-import-delims --delete-target-dir

#把数据从test数据库下的表person_all --query 模式 Sqoop 抽取到HDFS目录 /user/root/person_all 建议使用
sqoop import --connect --username root --password 111111 jdbc:mysql://192.168.164.25:3306/test --query “select id,name from person_all where id < 4 and $CONDITIONS” --target-dir    /user/root/person_all --split-by id -m 2 --delete-target-dir --hive-drop-import-delims

#数据从HDFS导入到RDB
sqoop export --connect --username root --password 111111 jdbc:mysql://192.168.164.25:3306/test --table person_all_test --export-dir /user/root/person_all --staging-table person_all_test_stage --clear-staging-table


③ 其他功能参数

–update-mode allowinsert
–update-key id
–input-null-string string类型的空值
–input-null-non-string 非string类型的空值
–staging-table
–clear-staging-table
–update-mode (allowinsert|updateonly) 更新模式,按照update key更新RDB中的数据,不会导致数据增加;allowinsert模式,当数据主键在RDB中不存在是转为insert操作
–update-key


④ 建表

create table person_all_test(id int,name varchar(10),sex varchar(10),age int,primary key(id));
create table person_all_test_stage(id int,name varchar(10),sex varchar(10),age int,primary key(id));


评论
登录后可评论
发布者
icon
LilJ
文章
14
问答
231
关注者
17
banner
关注星环科技
获取最新活动资讯

加入TDH社区版技术交流群

获取更多技术支持 ->

扫描二维码,立即加入