sqoop2 五分钟实例

摘自:http://sqoop.apache.org/docs/1.99.6/Sqoop5MinutesDemo.html

一、启动客户端

sqoop2-shell


二、设置服务端

 set server --host your.host.com --port 12000 --webapp sqoop

或者

set server --url http://sqoop2.company.net:80/sqoop

当 --url被指定后 --host,--port,--webapp将要被忽略

三、查看版本

show version --all


四、创建link

显示可用的连接

 show connector


1)根据connector的id创建 link1,下面的4为generic-jdbc-connector 的id

 create link -c 4


填写信息

Name: First Link


JDBC Driver Class: com.mysql.jdbc.Driver

JDBC Connection String: jdbc:mysql://mysql.server/database


Username: root

Password: *****

entry#回车

New link was successfully created with validation status OK and persistent id 1

2)创建link2,下面的4为hdfs-connector 的id

 create link -c 3


Name: Second Link


Link configuration

HDFS URI: hdfs://master:9000/

New link was successfully created with validation status OK and persistent id 2


五、创建job



create job -f 1 -t 2

Name: Sqoopy


 FromJob configuration


  Schema name:(Required)test

  Table name:(Required)testsqoop

  Table SQL statement:(Optional)

  Table column names:(Optional)

  Partition column name:(Optional) id        说明:这个我没有指定 测试的表如果没有主键会报错

  Null value allowed for the partition column:(Optional)

  Boundary query:(Optional)


ToJob configuration


  Output format:

   0 : TEXT_FILE

   1 : SEQUENCE_FILE

  Choose: 0

  Compression format:

   0 : NONE

   1 : DEFAULT

   2 : DEFLATE

   3 : GZIP

   4 : BZIP2

   5 : LZO

   6 : LZ4

   7 : SNAPPY

   8 : CUSTOM

  Choose: 0

  Custom compression format:(Optional)

  Output directory:(Required)/testsqoop


  Driver Config

  Extractors:(Optional) 2

  Loaders:(Optional) 2

  New job was successfully created with validation status OK  and persistent id 1


六、运行job

start job -j 1


七、查看状态


status job -j 1


八、完成后查看hdfs中是否有/testsqoop目录(说明:重新运行job好像需要删除存在的目录)


你可能感兴趣的:(sqoop实例)