11.5.15

Sqoop Usage

[cloudera@quickstart ~]$ sqoop help
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
15/05/11 07:15:54 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.4.0
usage: sqoop COMMAND [ARGS]

Available commands:
  codegen            Generate code to interact with database records
  create-hive-table  Import a table definition into Hive
  eval               Evaluate a SQL statement and display the results
  export             Export an HDFS directory to a database table
  help               List available commands
  import             Import a table from a database to HDFS
  import-all-tables  Import tables from a database to HDFS
  import-mainframe   Import datasets from a mainframe server to HDFS
  job                Work with saved jobs
  list-databases     List available databases on a server
  list-tables        List available tables in a database
  merge              Merge results of incremental imports
  metastore          Run a standalone Sqoop metastore
  version            Display version information

See 'sqoop help COMMAND' for information on a specific command.


1. 一个简单的例子

% sqoop import --connect jdbc:mysql://localhost/hadoopguide --table widgets -m 1

import: 命令字,从SQL数据库里导入数据
--connect <jdbc url>,指定connector
--table <table name>,指定数据库表名
-m 1,指定只使用一个mapper

这将会建立 hdfs://<host>/user/<username>/<tablename>目录,并成生一个结果:part-m-00000

2. 指定classname

% sqoop import --connect <jdbc url> --table <table name> --class-name <class name>

3. --query

4. Incremental Imports

5. 来自clouder quickstart的例子:

$ sqoop import-all-tables \
    -m 1 \
    --connect jdbc:mysql://quickstart:3306/retail_db \
    --username=retail_dba \
    --password=cloudera \
    --compression-codec=snappy \
    --as-avrodatafile \
    --warehouse-dir=/user/hive/warehouse

这里把整个库都转进来。





No comments: