Resolve an issue where the Sqoop import relationship Library updates the Federated primary key

Source: Internet
Author: User
Tags sqoop

[Author]: Kwu

Sqoop importing the relational library to update the federated primary key, import the data from hive into the relational library, if the Relational library table has a federated primary key, and you need to update the original data with the newly imported data.

1. Create a relational library table

CREATE TABLEtest123 (id INT not null,name VARCHAR (+) not null,age int,primary KEY (ID, name)) Engine=myisam DEFAULT CHARSET =utf8

2. Create Hive Table

drop table Default.test123;create table default.test123 (   ID int,   name                string,   age                  int) ROW FORMAT Delimited fields terminated by ' \ t ' STORED as textfile;

To import test data:

Insert Overwrite table default.test123 Select 1, ' Bill ', 5 from default.kwu_test limit 1;

3. Sqoop Import MySQL Database

Sqoop export  --connect jdbc:mysql://10.130.2.245:3306/test--update-key "Id,name"   --username Kwu  -- Password ' java.netphp '  --table test123  --fields-terminated-by ' \ t '--columns "Id,name,age"--export-dir/hive /warehouse/test123

Description: Key--update-key Specifies the value of the Federated primary key

To modify the test data:

Insert Overwrite table default.test123 Select 1, ' Bill ', 6 from default.kwu_test limit 1;


View the MySQL database in which age has been modified to 6.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Resolve an issue where the Sqoop import relationship Library updates the Federated primary key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.