Hive Learning seven "Sqoop Import from relational database extraction to HDFs"

Source: Internet
Author: User
Tags mysql in relational database table sqoop hadoop fs

First, what is Sqoop

Sqoop is an open source tool that is used primarily in Hadoop (Hive) and traditional databases (MySQL, PostgreSQL ...) Data can be transferred from one relational database (such as MySQL, Oracle, Postgres, etc.) to the HDFs in Hadoop, or the data in HDFs can be directed into a relational database.

Second, the characteristics of Sqoop

One of the highlights of Sqoop is the ability to import data from a relational database into HDFs through the mapreduce of Hadoop.

Iii. Sqoop Import Command

Place the JDBC driver for MySQL in the /opt/cloudera/parcels/cdh/lib/sqoop/lib directory.

Such as:

  

Reference Study Website:

  Http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.0/SqoopUserGuide.html

  Detailed command:

1. Basic grammar

1 Import (Generic-args) (import-args) $ sqoop-import (Generic-args) (import-args)

2. Basic commands

View URL:

  Http://archive.cloudera.com/cdh5/cdh/5/sqoop-1.4.4-cdh5.1.0/SqoopUserGuide.html

  Import control arguments for Sqoop import in

3. Case

  Way One:

Import data from table rpt_sale_daily into HDFs.

The target directory is: sqoop/rpt_sale_daily.

Import --connect jdbc:mysql://master:3306/test \--username root--password 123456--  --columns "Dateid,huodong,pv,uv"--where "dateid= ' 2015-08-28 '"--target-dir sqoop/- M 1

If the prompt sqoop/rpt_sale_daily directory already exists, execute:

Hadoop FS-RMR sqoop/rpt_sale_daily

Execution Result: if

20 data successfully imported, start testing IT Pro.

Execute code:

Hadoop Fs-cat sqoop/rpt_sale_daily/part-m-00000

Data such as:

The data in the relational database table rpt_sale_daily is as follows:

Comparison, the data is the same, successfully imported.

Way Two:

Transfer via opt file:

New Test.opt File:

1 Import2--Connect3Jdbc:mysql://192.168.0.115:3306/test4--username5 Root6--Password7 123456 8--Table9 rpt_sale_dailyTen--Columns One "ID,HUODONG,PVV,UVV"  A--where  - "id= ' 2015-08-28 '"  ---target-dir thesqoop/rpt_sale_daily --M1

Execution Instructions:

Sqoop Options-file test.opt

The execution process is the same as the result and method.

Hive Learning seven "Sqoop Import from relational database extraction to HDFs"

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.