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.
Figure 1
To list all databases use the following command
Figure 2
Now create the table employee in following manner
Figure 3
Now using following command you can see the table
Figure 4
Now add some records in this emp table
Figure 5
You can see the following records
Figure 6
Figure 7
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
Figure 8
Note: - while executing this command if you will get any access denied issues then first execute the following grant command
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
Figure 10
Now if you want to see these files stored in HDFS then execute the following command
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.
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.
If we want to specify the count of map task then we can use - - m option with numeric number.
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.
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
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:-
Figure 14
For any query you can send mail at info@techaltum.com Thanks