How to import data from MySQL database to Hadoop HDFS
1) First create a table named "customer" in MySQL
2) Insert data into the "customer" table.
3) Check the data in the table "customer"
4) Make sure to start Hadoop daemons before performing Sqoop operations.
5) Go to the directory in which Sqoop is installed and run the following line command.
bin/sqoop import -connect jdbc:mysql://localhost:3306/sampleJava -username root -password 12345 --table customer --target-dir /sqoopimport01 -m 1
If it runs successfully, then you will get following lines at the end.
which clearly shows 5 records have been retrieved from MySQL database. Now let's see whether these records have been imported to our HDFS.
6) Check whether a directory named as "/sqoopimport01" is created or not.
Earlier:
After running import:
As you can the required directory has been created.
7) Checking whether data has been imported to HDFS.
"/sqoopimport01" contains two files. "_SUCCESS" indicates that the process has been successfull and that import has been done.
Using "cat" command, we can see the data from "customer" table has been imported to HDFS and each record is seperated by comma.
No comments:
Post a Comment