{"id":687,"date":"2020-01-10T14:31:16","date_gmt":"2020-01-10T06:31:16","guid":{"rendered":"https:\/\/nj.transwarp.cn:8180\/?p=687"},"modified":"2020-01-10T14:31:16","modified_gmt":"2020-01-10T06:31:16","slug":"sqoop%e5%af%bc%e5%85%a5%e5%af%bc%e5%87%ba%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/kbwp.transwarp.cn\/?p=687","title":{"rendered":"sqoop\u5bfc\u5165\u5bfc\u51fa\u6570\u636e"},"content":{"rendered":"<h1>sqoop\u5bfc\u5165\u5bfc\u51fa\u6570\u636e<\/h1>\n<h3>\u6982\u8981\u63cf\u8ff0<\/h3>\n<p>\u6b64\u6587\u6863\u65e8\u5728\u4ecb\u7ecdsqoop\u64cd\u4f5cinceptor\u8fde\u63a5\u5176\u4ed6\u6570\u636e\u5e93\u7684\u5bfc\u5165\u5bfc\u51fa\u529f\u80fd<\/p>\n<h3>\u8be6\u7ec6\u8bf4\u660e<\/h3>\n<h4>1 \u6dfb\u52a0\u9a71\u52a8<\/h4>\n<p>1.1 \u5c06\u76f8\u5e94\u7684\u6570\u636e\u5e93\u9a71\u52a8\u653e\u7f6eTDH-CLIENT\/sqoop\/lib \u4e0b<br \/>\n\u4ee5oracle\u4e3a\u4f8b\uff1a<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566300782971.png\" alt=\"file\" \/><\/p>\n<h4>2 source TDH-Client\/init.sh<\/h4>\n<p><strong>2.1  \u6ca1\u6709\u5f00kerberos\u6267\u884c\uff1aexport HADOOP_USER_NAME=hive<br \/>\n2.2  \u5f00\u4e86kerberos\u6267\u884c\uff1akinit hive<\/strong><\/p>\n<h4>3 sqoop\u901a\u7528\u53c2\u6570\u8bf4\u660e<\/h4>\n<p>&#8211;username                                                \u6e90\u6570\u636e\u5e93\u540d\u79f0<br \/>\n&#8211;password                                                \u5bc6\u7801<br \/>\n&#8211;connect                                                 \u6570\u636e\u5e93JDBC\u8fde\u63a5\u4e32<br \/>\n&#8211;query                                                   SQL\u8bed\u53e5\uff0c\u5176\u4e2d where \\$CONDITIONS \u662f\u56fa\u5b9a\u5199\u6cd5<br \/>\n&#8211;target-dir                                              \u5199\u5165HDFS\u76ee\u5f55 \u540e\u9762\u8ddf\u7684HDFS\u76ee\u5f55\u9700\u8981\u786e\u8ba4\u7528\u6237\u6709\u5199\u6743\u9650<br \/>\n-m                          -m 4                          map\u4e2a\u6570\uff0c\u62bd\u6570\u7684\u7ebf\u7a0b\u6570\uff0c\u9ed8\u8ba4\u4e3a4  \u5f53-m\u5927\u4e8e1\u65f6\uff0c\u9700\u8981\u6307\u5b9a&#8211;split-by \u5b57\u6bb5<br \/>\n&#8211;split-by                  &#8211;split-by id                 \u6570\u636e\u5212\u5206\u5217\uff0c\u9ed8\u8ba4\u4e3a\u4e3b\u952e<br \/>\n&#8211;fetch-size                &#8211;fetch-size                  \u5355\u6b21\u53bb\u591a\u5c11\u6761\u8bb0\u5f55  \u4e00\u822c\u53d61000   \u53ef\u4ee5\u4e0d\u7528<br \/>\n&#8211;null-string               &#8211;null-string &#8216;\\N&#8217;           string\u7c7b\u578b\u7684\u7a7a\u503c<br \/>\n&#8211;null-non-string           &#8211;null-non-string &#8216;\\N&#8217;       \u975estring\u7c7b\u578b\u7684\u7a7a\u503c<br \/>\n&#8211;delete-target-dir         &#8211;delete-target-dir           \u5bfc\u5165\u6570\u636e\u524d\uff0c\u6e05\u7a7ahdfs\u76ee\u5f55<br \/>\n&#8211;field-terminated-by       &#8211;field-terminated-by &#8216;\\01&#8217;  \u5217\u5206\u9694\u7b26<br \/>\n&#8211;hive-drop-import-delims                                 \u53bb\u9664^A \\n \\r  \u7b49\u7279\u6b8a\u5b57\u7b26<\/p>\n<p>&#8211;append                    &#8211;append                      \u662f\u5426\u8bbe\u7f6e\u4e3a\u8ffd\u52a0\u589e\u91cf\u7684\u65b9\u5f0f\u5bfc\u5165,sqoop\u5c06\u628a\u6570\u636e\u5148\u5bfc\u5165\u5230\u4e00\u4e2a\u4e34\u65f6\u76ee\u5f55\u4e2d\uff0c\u7136\u540e\u91cd\u65b0\u7ed9\u6587\u4ef6\u547d\u540d\u5230\u4e00\u4e2a\u6b63\u5f0f\u7684\u76ee\u5f55\u4e2d\uff0c\u4ee5\u907f\u514d\u548c\u8be5\u76ee\u5f55\u4e2d\u5df2\u5b58\u5728\u7684\u6587\u4ef6\u91cd\u540d\u3002<br \/>\n-z                          -z,&#8211;compress                 \u538b\u7f29\u683c\u5f0f\uff0c\u9ed8\u8ba4\u4e3agzip<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566358998100.png\" alt=\"file\" \/><\/p>\n<h3>oracle<\/h3>\n<h4>1.4 \u5217\u51faXE\u4e0b\u6240\u6709\u7684\u8868<\/h4>\n<pre><code class=\"language-sql\">sqoop list-tables --connect \"jdbc:oracle:thin:@172.16.2.174:1521:XE\" --username xxxx --password xxxx<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566301050922.png\" alt=\"file\" \/><\/p>\n<h4>1.5 \u5bfc\u51fa\u8868xxxx.TEST   \uff08\u7528\u6237\u540d\u548c\u8868\u540d\u8981\u5927\u5199\uff0corc\u4e8b\u7269\u8868\u9700\u5148\u8f6c\u6362\u4e3atext\u8868\uff09<\/h4>\n<p>inceptor\u539f\u8868\uff1a<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566358105297.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-sql\">sqoop export --connect \"jdbc:oracle:thin:@172.22.44.1:1521:orcl\" --username jane --password 123 --table tp --export-dir \/inceptor1\/user\/hive\/warehouse\/default.db\/hive\/t3 --columns id,name --staging-table t1 --clear-staging-table -fields-terminated-by \"\\\\01\" --null-string '\\\\N' --null-non-string '\\\\N'<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566357552881.png\" alt=\"file\" \/><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566357586818.png\" alt=\"file\" \/><\/p>\n<p>oracle\u6700\u7ec8\u8868\u6570\u636e\uff1a<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566302284881.png\" alt=\"file\" \/><\/p>\n<h4>1.6 \u5bfc\u5165\u8868<\/h4>\n<p><strong>\u5bfc\u5165inceptor\u5fc5\u987b\u5148\u5bfc\u5165hdfs<\/strong><\/p>\n<p>oracle\u539f\u8868\u6570\u636e\uff1a<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566357856062.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-sql\">sqoop import --connect \"jdbc:oracle:thin:@172.22.44.1:1521:orcl\" --username jane --password 123 --target-dir \/tmp\/jane -m 1 --query \"select * from tp where \\$CONDITIONS\" --fields-terminated-by \"\\\\01\" --hive-drop-import-delims --null-string '\\\\N' --null-non-string '\\\\N'<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566302094900.png\" alt=\"file\" \/><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566302148789.png\" alt=\"file\" \/><br \/>\n\u6267\u884c\u540ehdfs\u6587\u4ef6\u5b58\u50a8\u7ed3\u6784:<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566358648268.png\" alt=\"file\" \/><br \/>\n\u5efa\u5916\u8868\u63a5\u6536hdfs\u6570\u636e\uff1a<\/p>\n<pre><code class=\"language-sql\">CREATE EXTERNAL TABLE user_info_tab (\nid STRING,\nname string\n)LOCATION 'hdfs:\/tmp\/jane';<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2019\/08\/image-1566302236465.png\" alt=\"file\" \/><\/p>\n<h3>\u5176\u4ed6\u4fe1\u606f<\/h3>\n<p>\u5728sqoop\u62bd\u53d6\u8fc7\u7a0b\u4e2d,\u5efa\u8bae\u4f7f\u7528\u4e00\u4e0b\u8303\u672c,\u80fd\u907f\u514d\u5f88\u591a\u9519\u8bef:<br \/>\n&#8211;fields-terminated-by &quot;\\01&quot;<br \/>\n&#8211;hive-drop-import-delims<br \/>\n&#8211;null-string &#8216;\\N&#8217;<br \/>\n&#8211;null-non-string &#8216;\\N&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>sqoop\u5bfc\u5165\u5bfc\u51fa\u6570\u636e \u6982\u8981\u63cf\u8ff0 \u6b64\u6587\u6863\u65e8\u5728\u4ecb\u7ecdsqoop\u64cd\u4f5cinceptor\u8fde\u63a5\u5176\u4ed6\u6570\u636e\u5e93\u7684\u5bfc\u5165\u5bfc\u51fa\u529f\u80fd \u8be6 ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/kbwp.transwarp.cn\/?p=687\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"_links":{"self":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=687"}],"version-history":[{"count":2,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":3517,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=\/wp\/v2\/posts\/687\/revisions\/3517"}],"wp:attachment":[{"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kbwp.transwarp.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}