What is Sqoop Import Command

In SQOOP import command is used to import RDBMS data into HDFS. Using import command we can import a particular table into HDFS.

In this example I will show how we can import MySQL database table into HDFS.

First of all create database using following command.

	Import Command in sqoop
		Figure 1

To list all databases use the following command

	Import Command Result
		Figure 2

Now create the table employee in following manner

	import command in Apache sqoop
		Figure 3

Now using following command you can see the table

	sqoop import command
		Figure 4

Now add some records in this emp table

	apache sqoop import
		Figure 5

You can see the following records

	sqoop tutorial
		Figure 6
	sqoop introduction
		Figure 7

How to use Import Command in sqoop

Now you can import this emp table into hdfs by using following sqoop import command

Sqoop import - - connect jdbc:mysql://localhost:3306/databasename - - username u_name - -password pwd - - table table_name

	hadoop import data
		Figure 8

Note: - while executing this command if you will get any access denied issues then first execute the following grant command

	importing data into hadoop
		Figure 9

If command will run successfully then you will get final following output.

Note: - I am showing the last screen shot of the output window as its very large image to display

	loading sql data into hadoop
		Figure 10

Now if you want to see these files stored in HDFS then execute the following command

	how to load data into hadoop
		Figure 11

Note: - if we don’t specify the output directory then sqoop creates the directory with the name of table which you have uploaded in HDFS and divide the data in part-m-00000, part-m-00001 so on.

	hadoop command result
		Figure 12

As you can see the figure its showing it launched 3 map task so three output file will be get generated and i.e part-m-00000, part-m-00001 and part-m-00002.

Import command with - -m option

If we want to specify the count of map task then we can use - - m option with numeric number.

Import command with - - target-dir

As in the previous example has seen the example in which we didn’t assign the target directory. If we want then using target-dir option we can specify the directory.

		target-dir result
		Figure 13

In this way you can check the arguments of different commands of SQOOP

When we execute this command you will see only one map task will be get executed.

And if you will list the directory by using following command you will find only one output file i.e Part-m-00000

Import command with - - where

In our previous example we see how we can import complete table in HDFS. SQOOP import with where clause allows us to import specific records in HDFS.

For example I want to import only those records who are having age equal and greater than 26. In our emp table we have 2 records having age greater than equal to 26.

So we will write sqoop import command using where clause in the following manner:-

		Import where result
		Figure 14

Email Address

For any query you can send mail at info@techaltum.com