Hadoop (eight)-Sqoop installation and use

Source: Internet
Author: User
Tags sqoop

Installed on a single node is available.

1. Upload Sqoop using WINSCP

2. Installation and Configuration
Add Sqoop to environment variable
Copy the database connection driver Mysql-connector-5.1.8.jar to the $sqoop_home/lib


### First class: Data in the database is imported into HDFs
Sqoop Import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123--table Trade_detail--colum NS ' ID, account, income, expenses '

Specify the output path, specify the data delimiter
Sqoop Import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123--table Trade_detail--targe T-dir '/sqoop/td '--fields-terminated-by ' \ t '

Specify map number-M
Sqoop Import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123--table Trade_detail--targe T-dir '/sqoop/td1 '--fields-terminated-by ' \ t '-M 2

Add where condition, note: The condition must be enclosed in quotation marks
Sqoop Import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123--table Trade_detail--where ' Id>3 '--target-dir '/SQOOP/TD2 '

Add a query statement (use \ Wrap statement)
Sqoop Import--connect jdbc:mysql://192.168.1.10:3306/itcast--username root--password 123 \
--query ' SELECT * from Trade_detail where ID > 2 and $CONDITIONS '--split-by trade_detail.id--target-dir '/sqoop/td3 '

Note: If you use the--query command, it is important to note that the argument after the where, and $CONDITIONS This parameter must be added
And there is the difference between single and double quotes, if--query is followed by double quotes, then you need to add \ \ \ $CONDITIONS
If you set the number of maps to 1---M 1, without adding--split-by ${tablename.column}, you need to add a

### Type II: Export data from HDFs to the database (do not forget to specify delimiters)
Sqoop export--connect jdbc:mysql://192.168.8.120:3306/itcast--username root--password 123--export-dir '/td3 '--table Td_bak-m 1--fields-terminated-by ', '

Three. Configure MySQL remote connection
GRANT all privileges the itcast.* to ' root ' @ ' 192.168.1.201 ' identified by ' 123 ' with GRANT OPTION;
FLUSH privileges;

GRANT all privileges on * * to ' root ' @ '% ' identified by ' 123 ' with GRANT OPTION;
FLUSH Privileges

Hadoop (eight)-Sqoop installation and use

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.