Sqoop Common Commands

Source: Internet
Author: User
Tags mysql database sqoop

1. List all databases in MySQL database

Sqoop list-databases--connect jdbc:mysql://localhost:3306/-username Dyh-password 000000

2. Connect MySQL and list the tables in the database

Sqoop list-tables--connect jdbc:mysql://localhost:3306/test--username dyh--password 000000

3. Copy the table structure of the relational data into hive

Sqoop create-hive-table--connect jdbc:mysql://localhost:3306/test--table users--username dyh

--password 000000--hive-table users--fields-terminated-by "\0001"--lines-terminated-by "\ n";

parameter Description:

--fields-terminated-by "\0001" is to set the delimiter between each column, "\0001" is 1 in the ASCII code, it is also the default inline delimiter for hive, and the default inline delimiter for Sqoop is ","

--lines-terminated-by "\ n" sets the delimiter between each line, where the newline character is the default delimiter;


Note: Only the structure of the table is copied, the contents of the table are not copied
4. Import data from a relational database into a hive table

Sqoop import--connect jdbc:mysql://localhost:3306/test--username dyh--password 000000

--table users--hive-import--hive-table users-m 2--fields-terminated-by "\0001";

parameter Description:

-M 2 means that two map jobs are executed;

--fields-terminated-by "\0001" should be consistent with the creation of hive tables;


5. Import table data from hive into MySQL database table

Sqoop export--connect jdbc:mysql://192.168.20.118:3306/test--username dyh--password 000000

--table Users--export-dir/user/hive/warehouse/users/part-m-00000

--input-fields-terminated-by ' \0001 '


Attention:

1, before the import, the table Userst in MySQL must have been mentioned created.

2, Jdbc:mysql://192.168.20.118:3306/test in the IP address changed to localhost will report abnormal, specifically see my previous post

6. Import the data from the relational database into the Hive table, using the--query statement

Sqoop import--append--connect jdbc:mysql://192.168.20.118:3306/test--username dyh--password 000000--query "SELECT ID , age,name from Userinfos where \ $CONDITIONS "-M 1--target-dir/user/hive/warehouse/userinfos2--fields-terminated-by", ";


7. Import the data from the relational database into the Hive table,--columns the--where statement using

Sqoop import--append--connect jdbc:mysql://192.168.20.118:3306/test--username dyh--password 000000--table Userinfos --columns "Id,age,name"--where "ID > 3 and (age = in or age =)"-M 1--target-dir/user/hive/warehouse/userinfos 2--fields-terminated-by ",";

Note:--target-dir/user/hive/warehouse/userinfos2 can be replaced with--hive-import--hive-table Userinfos2




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.