sqoop export\import 参数
sqoop export\import 参数
export
参数说明:
--validate <class-name>启用数据副本验证功能,仅支持单表拷贝,可以指定验证使用的实现类
--validation-threshold <class-name>指定验证门限所使用的类
--direct 使用直接导出模式(优化速度)
--export-dir <dir>导出过程中HDFS源路径
-m,--num-mappers <n>使用n个map任务并行导出
--table <table-name>导出的目的表名称
--call <stored-proc-name>导出数据调用的指定存储过程名
--update-key <col-name>更新参考的列名称,多个列名使用逗号分隔
--update-mode <mode>指定更新策略,包括:updateonly(默认)、allowinsert
--input-null-string <null-string>使用指定字符串,替换字符串类型值为null的列
--input-null-non-string <null-string>使用指定字符串,替换非字符串类型值为null的列
--staging-table <staging-table-name>在数据导出到数据库之前,数据临时存放的表名称
--clear-staging-table清除工作区中临时存放的数据
--batch使用批量模式导出
mysql:
全量导出:
//例1
//先清空mysql这张表
#!/bin/bash
sqoop eval --connect "jdbc:mysql://172.***.***.170:3309/p_b?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true" \
--username *** \
--password *** \
--e "DELETE from t_kp_***"
//再将数据推送到mysql
sqoop export \
--connect "jdbc:mysql://172.***.***.170:3309/p_b?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true" \
--username *** \
--password *** \
--table t_kp_*** \
--update-key cno \
--update-mode allowinsert \
--input-fields-terminated-by "\001" \
--hcatalog-database os \
--hcatalog-table os_***_kp_***_al \
--columns="id,company,city" \
--num-mappers 1
--input-null-string '\\N'
--input-null-non-string '\\N'
//例2
sqoop export \
--connect "jdbc:mysql://****/ln?useUnicode=true&characterEncoding=utf-8" \
--username *** \
--password *** \
--table t_test_mysql \
--update-mode allowinsert \
--input-fields-terminated-by "\001" \
--hcatalog-database os \
--hcatalog-table os_table \
--columns="id,company,city" \
--num-mappers 1 \
--input-null-string '\\N' \
--input-null-non-string '\\N' \
--null-string '\\N' \
--null-non-string '\\N'
按天导出到mysql:
#!/bin/bash
#删除数据
effective_time=`date -d "-1days" +%Y-%m-%d` #这里先定义一个变量(比如是昨天)
sqoop eval --connect "jdbc:mysql://172.**.***.170:3309/p_b?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true" \
--username p_b \
--password i6h*******jpl \
--e "delete from t_sdssfs where left(statistic_time,10) ='$effective_time'"
#导出数据 insert到mysql表
sqoop export \
--connect "jdbc:mysql://172.**.***.170:3309/p_b?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true" \
--username p_b \
--password i6h*******jpl \
--table t_sdssfs \
--input-fields-terminated-by "\001" \
--hcatalog-database dw \
--hcatalog-table t_sdssfs \
--columns="brand,functions,count_ppv,count_uuv,statistic_time,create_time" \
--num-mappers 1 \
--input-null-string '\\N' \
--input-null-non-string '\\N'
思路是删除具体哪天的数据,然后将“正确的”数据,导出到新表即可
sqlserver:
把数据从hdfs导回到sqlserver
把数据从hdfs导回到sqlserver,从hive导出也和这个一样,因为都是文本文件,hbase的话,也是不支持直接的,需要通过和hive结合,才能导出。
sqoop export --connect 'jdbc:sqlserver://192.***.***.105:1433;username=***;password=***;database=SAMS' \
--table ST_Statistics2 --export-dir /user/cenyuhai/sams
参考:
sqoop export \
--connect jdbc:microsoft:sqlserver://10.134.777.844/ABC_Finance \
--table ABC_PAYE_TYP \
--username myUser \
--P \
--m 1 \
--export-dir /test/financial/abc/pmt_typ/000001_0
--driver com.microsoft.sqlserver.jdbc.SQLServerDriver
参考:
https://stackoverflow.com/questions/54702585/hadoop-sqoop-export-to-sql-server-database-driver-placement-and-configuratio
参考:https://yq.aliyun.com/articles/60291
import
--append 将数据追加到hdfs中
--as-avrodatafile 将文件导入到一个avro文件中
--as-sequencefile 将数据导入到一个sequencefile中
--as-textfile 将数据导入到一个文本文件
--boundary-query 边界查询,导入的数据为该参数的值(一条sql语句)所执行的结果区间内的数据
--columns 指定要导入的列,用逗号分隔
--direct 使用关系型数据库自带的导入导出工具
--direct-split-size 对direct导入的数据进行切分字节,达到阈值就是一个问题件
--inline-lob-limit 设置大对象数据类型的最大值
--m或–num-mappers 启动多少个map,默认4个
--query或--e 跟sql语句,使用时必须伴随参数 --taget-dir,--hive-table
--split-by 跟列名,按照一列来切分表的工作单元
--table 跟表名
--target-dir 指定hdfs路径
--warehouse-dir 与--target-dir参数不能共用,导入数据到hdfs指定目录
--where 从关系型数据库导入数据时的条件
--z或--compress 允许压缩
--compression-codec 指定压缩格式
--null-string 字符串类型如果为null,替换成指定字符串
--null-non-string 非字符串类型如果为null,替换成指定字符串
--check-column 增量导入判断的列名
--incremental 参数为append或者lastmodified
--last-value 指定一个值,用于标记增量导入的位置
从mysql导出到hive,每次导出全量覆盖:(–hive-*为公共参数)
sqoop公共参数链接
sqoop import
–connect xx
–username xx
–password xx
–table tableName1
–fields-terminated-by ‘\001’
–delete-target-dir
–num-mappers 1
–hive-import
–hive-overwrite
–hive-database dbName
–hive-table tableName2 \

浙公网安备 33010602011771号