sqoop Sqoop Import Import RDBMS Table to HDFS


Example

sqoop import \
--connect <rdbms-jdbc-url> \
--username <username> \
--password <password> \
--table <table-name>

Example with Mysql:

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table employees

CSV file with the imported data will be created under employees directory under home directory.

Inspect using command:

hadoop fs -cat <hdfs-home-dir>/employees/part-m-* 

Import to a particular directory in HDFS

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table emplyoees \
--target-dir /dev/data/employees

This will generate CSV file under /dev/data/employees directory.

Specify parent HDFS directory for Sqoop job

sqoop import \
--connect jdbc:mysql://mysql.example.com/testdb \
--username root \
--password root \
--table emplyoees \
--warehouse-dir /dev/warehouse/

--warehouse-dir tag in above command will change your home directory to /dev/warehouse/