利用Sqoop从HDFS导出数据到DB
发布日期:2021-11-04 22:04:09
浏览次数:4
分类:技术文章
本文共 2900 字,大约阅读时间需要 9 分钟。
需求
目标
语法
hadoop分析完的结果数据最终要呈现给用户,其中一些结果可能需要导入DB。 这里大部分是insert操作,但是有些时候可能还需要update。最好是如果存在就update,不存在就insert。
目标
将一系列HDFS中的文件导出到RDBMS。这里要求RDBMS的表必须提前创建。 文件中的数据通过指定的分割符被解析为表中的记录。 支持insert、update和insertOrUpdate
语法
* 命令 sqoop-export或sqoop export * 通用参数 --connect <jdbc-uri> 指定JDBC链接串 --connection-manager <class-name> 指定使用的connection manager class --driver <class-name> 手动指定用户的JDBC driver class -P 从console读入连接DB的password
--password <password> 设置连接DB的password --username <username> 设置连接DB的username --connection-param-file <filename> 可选的连接DB的properties文件 --verbose 运行时输出更多信息 --hadoop-home <dir> 覆盖$HADOOP_HOME --help输出用法介绍 * 导出参数 --direct Use direct export fast path --export-dir <dir> 为了export的HDFS源路径 -m,--num-mappers <n> 使用n个map tasks去并行的执行export,默认为4 --table <table-name> 导入的Table --update-key <col-name> update时使用的条件列,多个列时用逗号分隔 -update-mode <mode> update时,发现新记录的处理方式,默认updateonly,还可以设置allowinsert --input-null-string <null-string> The string to be interpreted as null for string columns --input-null-non-string <null-str> The string to be interpreted as null for non-string columns --staging-table <staging-table-name> The table in which data will be staged before being inserted into the destination table. --clear-staging-table Indicates that any data present in the staging table can be deleted. --batch Use batch mode for underlying statement execution. * Input解析参数 --input-enclosed-by <char> Sets a required field encloser --input-escaped-by <char> Sets the input escape character --input-fields-terminated-by <char> Sets the input field separator --input-lines-terminated-by <char> Sets the input end-of-line character --input-optionally-enclosed-by <char> Sets a field enclosing character * 输出行格式参数 --enclosed-by <char> Sets a required field enclosing character --escaped-by <char> Sets the escape character --fields-terminated-by <char> Sets the field separator character --lines-terminated-by <char> Sets the end-of-line character --mysql-delimiters Uses MySQL’s default delimiter set: fields: , lines: \n escaped-by: \ optionally-enclosed-by: ' --optionally-enclosed-by <char> Sets a field enclosing character * 代码生成参数 --bindir <dir> Output directory for compiled objects --class-name <name> Sets the generated class name.
This overrides --package-name. When combined with --jar-file, sets the input class. --jar-file <file> Disable code generation; use specified jar --outdir <dir> Output directory for generated code --package-name <name> Put auto-generated classes in this package --map-column-java <m> Override default mapping from SQL type to Java type for configured columns.
最佳示例
sqoop export --connect jdbc:oracle:thin:@xxx:1521:xxx --username xxx --password xxx\
--export-dir /user/hadoop/stat/*\
-m 1 \
--table NS_SLLOG_CLIENT_SUM_OS \
--update-key ACTIVITYTIME,CLIENT_VER,OS \
--update-mode allowinsert \
--input-fields-terminated-by '\t' \
--outdir jobs \
--package-name com.xxxx.sqoop
转载地址:https://blog.csdn.net/xiaochawan/article/details/7994556 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月02日 19时48分48秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
python模块的定义,和模块的作用域
2019-04-26
面向对象,即class类,类的封装,属性的类别划分,
2019-04-26
面向对象的继承和多态,剖析对象的信息(获取相关信息),类属性和实例属性
2019-04-26
JS的语句标识,注释,区分大小写
2019-04-26
JS的变量,使用strict模式
2019-04-26
对象,对象属性和方法
2019-04-26
Ubuntu的安装,搜狗输入法的安装
2019-04-26
itertools处理迭代
2019-04-26
iterable对象 yeield
2019-04-26
一些实用的快捷键
2019-04-26
添加打印机,在windows上面和Ubuntu上面
2019-04-26
Prepare the data
2019-04-26
scipy.misc.imresize改变图像的大小
2019-04-26
np.all的实例应用
2019-04-26
custom_transforms
2019-04-26