Thursday, September 13, 2018

Sqoop - Command (Part 1)

We have gone through the Sqoop architecture in our last post.In this blog post , we will focus on some of the sqoop commands.

Sqoop help list-databases :- It will display all the commands that are available with the list-databases.

 
Listing Databases in My SQL :- It will show all the databases that are available in the MY SQL .

Syntax :- sqoop list-databases --connect jdbc:mysql://localhost/ --username --password

Note that it is advisable to provide the password in the console ,this can be achieved by writing
 -P in the above command.

sqoop list-databases --connect jdbc:mysql://localhost/ --username root -P

List Tables in a specified database :- It will display all the tables that are available in a particular database.
Syntax:-  sqoop list-tables --connect jdbc:mysql://localhost/databasename  --username -password
 
Table to read and store :- It will import the specified table into the HDFS directory.

Syntax:- sqoop import --connect jdbc:mysql://localhost/databasename --username -P --table tablename
We have fired the below command and got the output.
sqoop import --connect jdbc:mysql://localhost/company --username root -password root --table department
 
The details of the file that has been generated in the HDFS.The files will be in the form part-m-0000 .
 
The below are the contents of the file.
 

Storing data in a particular directory in HDFS :- We can import the table and store it in a particular directory in the HDFS.
Syntax :- sqoop import --connect jdbc:mysql://localhost/databasename --username -P --target-dir dirname  --table tablename
 

Note : - If the output directory already exists . we can get an error message.

No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...