mirror of
https://github.com/apache/sqoop.git
synced 2025-05-08 02:50:38 +08:00

From: Thomas White <tomwhite@apache.org> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149843 13f79535-47bb-0310-9956-ffa450edef68
59 lines
2.4 KiB
Plaintext
59 lines
2.4 KiB
Plaintext
|
|
////
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
this work for additional information regarding copyright ownership.
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
(the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
////
|
|
|
|
|
|
Exporting to a Database
|
|
-----------------------
|
|
|
|
In addition to importing database tables into HDFS, Sqoop can also
|
|
work in "reverse," reading the contents of a file or directory in
|
|
HDFS, interpreting the data as database rows, and inserting them
|
|
into a specified database table.
|
|
|
|
To run an export, invoke Sqoop with the +--export-dir+ and
|
|
+--table+ options. e.g.:
|
|
|
|
----
|
|
$ sqoop --connect jdbc:mysql://db.example.com/foo --table bar \
|
|
--export-dir /results/bar_data
|
|
----
|
|
|
|
This will take the files in +/results/bar_data+ and inject their
|
|
contents in to the +bar+ table in the +foo+ database on +db.example.com+.
|
|
The target table must already exist in the database. Sqoop will perform
|
|
a set of +INSERT INTO+ operations, without regard for existing content. If
|
|
Sqoop attempts to insert rows which violate constraints in the database
|
|
(e.g., a particular primary key value already exists), then the export
|
|
will fail.
|
|
|
|
As in import mode, Sqoop will auto-generate an interoperability class
|
|
to use with the particular table in question. This will be used to parse
|
|
the records in HDFS files before loading their contents into the database.
|
|
You must specify the same delimiters (e.g., with +--fields-terminated-by+,
|
|
etc.) as are used in the files to export in order to parse the data
|
|
correctly. If your data is stored in SequenceFiles (created with an import
|
|
in the +--as-sequencefile+ format), then you do not need to specify
|
|
delimiters.
|
|
|
|
If you have an existing auto-generated jar and class that you intend to use
|
|
with Sqoop, you can specify these with the +--jar-file+ and +--class-name+
|
|
parameters. Providing these options will disable autogeneration of a new
|
|
class based on the target table.
|
|
|
|
|