Chapter 2
第 2 章
Sqoop is a collection of related tools. To use Sqoop, you specify the tool you want to use and the arguments that control the tool.
- Sqoop 是一组相关工具的集合。要使用 Sqoop,你需要指定想要使用的工具以及控制该工具的参数。
Sqoop-Tool - The advantage of using alias scripts is that you can avoid spelling errors by pressing the [tab] key twice when typing commands after Sqoop-
- Sqoop-Tool - 使用别名脚本的优势在于,在输入 Sqoop- 后按两次 [tab] 键可以避免拼写错误。
Sqoop’s versioning tool is one of the simplest, so simple that it doesn’t even require any parameters to be provided
- Sqoop 的版本控制工具是最简单的工具之一,简单到甚至不需要提供任何参数。
sqoop version
sqoop-version
To control the operation of each Sqoop tool, you use generic and specific arguments usages:
- 要控制每个 Sqoop 工具的操作,你需要使用通用参数和特定参数:
1 | sqoop import [GENERIC-ARGS] [TOOL-ARGS] |
a. Common arguments:
- 常用参数:
| Argument | Description | 说明 |
|---|---|---|
--connect <jdbc-uri> |
Specify JDBC connect string | 指定 JDBC 连接字符串 |
--connect-manager <class-name> |
Specify connection manager class to use | 指定要使用的连接管理器类 |
--driver <class-name> |
Manually specify JDBC driver class to use | 手动指定要使用的 JDBC 驱动类 |
--hadoop-mapred-home <dir> |
Override $HADOOP_MAPRED_HOME | 覆盖 $HADOOP_MAPRED_HOME 环境变量 |
--help |
Print usage instructions | 打印使用帮助说明 |
--password-file |
Set path for file containing authentication password | 设置包含身份验证密码的文件路径 |
-P |
Read password from console | 从控制台读取密码 |
--password <password> |
Set authentication password | 设置身份验证密码 |
--username <username> |
Set authentication username | 设置身份验证用户名 |
--verbose |
Print more information while working | 运行过程中打印更多详细信息(冗余模式) |
--hadoop-home <dir> |
Deprecated. Override $HADOOP_HOME | 已弃用。覆盖 $HADOOP_HOME 环境变量 |
--connection-param-file <filename> |
Provide optional properties file for connection parameters | 为连接参数提供可选的属性文件 |
--relaxed-isolation |
Set connection transaction isolation to read uncommitted mappers | 将连接事务隔离级别设置为“读未提交”(read uncommitted),供 mapper 使用 |
b. Generic Hadoop options
- 通用 Hadoop 选项
| Argument | Description | 说明 |
|---|---|---|
-conf <configuration file> |
specify an application configuration file | 指定应用程序配置文件 |
-D <property-value> |
use value for given property | 使用给定属性的值 |
-fs <local namenode:port> |
specify a namenode | 指定 namenode |
-jt <local jobtracker:port> |
specify a job tracker | 指定 job tracker |
-files <comma separated list of files> |
specify comma separated files to be copied to the map reduce cluster | 指定要复制到 MapReduce 集群的逗号分隔文件列表 |
-libjars <comma separated list of jars> |
specify comma separated jar files to include in the classpath. | 指定要包含在类路径 (classpath) 中的逗号分隔 jar 文件列表 |
-archives <comma separated list of archives> |
specify comma separated archives to be unarchived on the compute machines. | 指定要在计算机器上解压的逗号分隔归档文件列表 |
- The general command line syntax is:
- 通用命令行语法为:
1 | bin/hadoop command [genericOptions] [commandOptions] |
You must supply the generic arguments -conf, -D, and so on after the tool name but before any tool-specific arguments (such as --connect). Note that generic Hadoop arguments are preceded by a single dash character (-), whereas tool-specific arguments start with two dashes (–), unless they are single character arguments such as -P.
- 你必须在工具名称之后但在任何特定于工具的参数(例如 --connect)之前提供通用参数 -conf、-D 等。请注意,通用 Hadoop 参数前面有一个破折号 (-),而特定于工具的参数以两个破折号 (–) 开头,除非它们是单个字符参数(例如 -P)。
The -conf, -D, -fs and -jt arguments control the configuration and Hadoop server settings.
- -conf、-D、-fs 和 -jt 参数控制配置和 Hadoop 服务器设置。
You can use alias scripts that specify the sqoop-(toolname) syntax. For example, the script sqoop-import, or sqoop-export, etc. each selects a specific tool. These scripts are placed in the bin directory of the Sqoop installation directory:
- 你可以使用指定 sqoop-(toolname) 语法的别名脚本。例如,脚本 sqoop-import 或 sqoop-export 等分别选择特定的工具。这些脚本放置在 Sqoop 安装目录的 bin 目录中:
Available commands:
- 可用命令:
| Argument | Description | 说明 |
|---|---|---|
| codegen | Generate code to interact with database records | 生成代码以与数据库记录交互 |
| create-hive-table | Import a table definition into Hive | 将表定义导入 Hive |
| eval | Evaluate a SQL statement and display the results | 评估 SQL 语句并显示结果 |
| export | Export an HDFS directory to a database table | 将 HDFS 目录导出到数据库表 |
| help | List available commands | 列出可用命令 |
| import | Import a table from a database to HDFS | 将表从数据库导入 HDFS |
| import-all-tables | Import tables from a database to HDFS | 将多个表从数据库导入 HDFS |
| import-mainframe | Import datasets from a mainframe server to HDFS | 将数据集从大型机服务器导入 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 | 运行独立的 Sqoop 元存储 |
| version | Display version information | 显示版本信息 |
List Databases Tool
- 列出数据库工具
The sqoop-list-databases tool is used to list which databases are available in a given database. This tool makes it easy to check whether the connection between Sqoop and a database server is successful. Since you need to specify the jdbc-uri of the database you are connecting to, as well as the username and password you need to use to establish a connection to the database, you need to specify these parameters when using the list-databases tool. Usage:
- sqoop-list-databases 工具用于列出给定数据库中可用的数据库。该工具可以轻松检查 Sqoop 与数据库服务器之间的连接是否成功。由于你需要指定要连接的数据库的 jdbc-uri,以及建立数据库连接所需的用户名和密码,因此在使用 list-databases 工具时需要指定这些参数。用法:
1
sqoop list-databases [General Parameters) [Tool Parameters]
List database schemas available on a MySQL server:
- 列出 MySQL 服务器上可用的数据库模式:
1 | sqoop list-databases --connect jdbc:mysql://localhost --username name -P |
List All Tables Tool
- 列出所有表工具
Similar to the sqoop-list-tables tool used to list all tables of a given database.
- 类似于用于列出给定数据库所有表的 sqoop-list-tables 工具。
Usage:
- 用法:
1 | sqoop list-tables [generic-args] [list-tables-args] |