Sqoop使用总结

Import

导入整个表mysql

目标目录:--target-dirsql

          --warehouse-dir  (parentdir,当导入多个表的时候,不须要屡次指定输出目录)apache

导入表的部分数据安全

--where (用来过滤数据)并发

安全问题,密码隐藏 –p   (--password-file(指定文件的权限))app

指定导出的文件类型 (text,sequenceFile)工具

压缩 –compress (gz,bz2等)oop

run faster   --direct (使用native utilities export tools)post

 

控制并发 controlling parallelism  --num-mappers (要找到合适的并发数,不合适会致使表的查询降低)spa

 

Null值的替换 –null-string ‘\\N’ \

            --null-non-string (将字符串null和非字符串null替换为\N)

 

导出全部的表,排除一些表:--import-all-tables

                          --exclude-tables

 

将新的值append到目的表中 –check-column id

                          --last-value (指定列,指定最后更新的值)

 

 

Import from two tables

                --query “sql” 代替instead of –-table

修改job的名称: 当用—query没有指定时 ,默认是QueryResukt.jar

                    --table 没有指定时,默认是Table.jar

 

Export

to the relational database

insert operation mapreduce job

Inserting data in Batches

     --batch

       --Dsqoop.export.records.per.statement=10

import temporary Table ->real table

                   --staging-table

updating an Existing dataset(changed row) update-key

 

update or insert(upsert) at same time update-mode allowinsert

Exporting into a Subset of columns  --columns x,xx,xxx

默认地,sqoop假设hdfs数据包括和导出到的表相同的顺序和数量的列

Encoding the NULL value differently

         --input-null-string  \\N

         --input-null-non-string \\N

export corrupted data  :input format not correct

 

Other

Oozie工具

Import data directly into hive

--hive-import

change the hive type of column id to string

--map-column-hive id=STRING

refresh hive table data   hive-overwrite

 

using partitioned hive table

--hive-import\

--hive-partition-key day\

--hive-partition-value 2014-12-25

remove all delims like \n,\t,\01 from string based columns

--hive-drop-import-delims

 

import data to Hbase (real-time database)

sqoop import \

--connect jdbc:mysql: //127.0.0.1/sqoop \

--username sqoop \

--password sqoop \

--table cities \

--columns ‘id,name’

--hbase-table cities \

--column-family world

 

Boolean instead of

--boolean-true-string 1

--boolean-false-string 0

 

hbase不容许插入空值

 

improving performance

须要更多的时间导入hbase

提早建立hbase create ‘city’,’word’,{NUMREGIONS=>20,SPLITALGO=>’HexString Split’}

每一个新建的hbase表只有一个region只能被一个region server服务,只能被一个物理节点访问。

 

use schema

sqoop import \

--connect jdbc:postgresql:/127.0.0.1/database \

--username sqoop \

--password sqoop \

--table cities \

-- \

--schema us

 

 

know more about sqoop,read apache sqoop Cookbook or to http://sqoop.apache.org/

相关文章
相关标签/搜索