Sqoop 简明教程
Sqoop - Import All Tables
本章介绍如何将所有表从 RDBMS 数据库服务器导入到 HDFS。每个表数据存储在单独的目录中,目录名称与表名称相同。
This chapter describes how to import all the tables from the RDBMS database server to the HDFS. Each table data is stored in a separate directory and the directory name is same as the table name.
Syntax
以下语法用于导入所有表。
The following syntax is used to import all tables.
$ sqoop import-all-tables (generic-args) (import-args)
$ sqoop-import-all-tables (generic-args) (import-args)
Example
我们以从 userdb 数据库导入所有表为例。数据库 userdb 包含的表列表如下。
Let us take an example of importing all tables from the userdb database. The list of tables that the database userdb contains is as follows.
+--------------------+
| Tables |
+--------------------+
| emp |
| emp_add |
| emp_contact |
+--------------------+
以下命令用于从 userdb 数据库导入所有表。
The following command is used to import all the tables from the userdb database.
$ sqoop import-all-tables \
--connect jdbc:mysql://localhost/userdb \
--username root
Note - 如果你在使用 import-all-tables,那么数据库中的每个表都必须有一个主键字段。
Note − If you are using the import-all-tables, it is mandatory that every table in that database must have a primary key field.
以下命令用于将所有表数据验证到 HDFS 中的 userdb 数据库。
The following command is used to verify all the table data to the userdb database in HDFS.
$ $HADOOP_HOME/bin/hadoop fs -ls
它将会向你展示 userdb 数据库中的表名称列表作为目录。
It will show you the list of table names in userdb database as directories.