Sqoop term is combination of SQL and Hadoop i.e SQL + HADOOP = SQOOP. Sqoop was initially created by Cloudera and now it is maintained by Apache. Sqoop was created to import & export data seamlessly in & out of HDFS from & to RDBMS systems.
Sqoop provide many utilities apart of just import/export data
Sqoop Command |
Description |
help |
List all Sqoop commands |
version |
Display Sqoop version |
list-databases |
List available databases on connected database |
list-tables |
List available tables in a connected database |
eval |
Execute a SQL statement and return the results |
export |
Export an HDFS directory/file to a database table |
import |
Import a table from a database to HDFS |
import-all-tables |
Import tables from a database to HDFS |
codegen |
Generate code which will used by Sqoop Import/Export |
job |
Create Sqoop jobs to perform repeated task |
Argument |
Description |
connect |
RDBMS connection URL used by Sqoop to connect to database server (with or without database name). |
username |
This is the username of database to be used for connecting database. |
password |
This is the password of username used for connecting database. |
driver |
This is jdbc driver class for the underlying database. |
sqoop version Output Sqoop 1.4.7
Syntax: sqoop help [command] Example 1: sqoop help Example 2: sqoop help import Example 3: sqoop help export Example 4: sqoop help eval
sqoop list-databases \ --connect jdbc:mysql://localhost:3306 \ --username root \ --password mysqlrootpassword
sqoop list-tables \ --connect jdbc:mysql://localhost:3306/demo_db \ --username root \ --password mysqlrootpassword
sqoop eval \ --connect jdbc:mysql://localhost:3306/demo_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --query "SELECT * FROM order_items LIMIT 10"
sqoop import-all-tables \ --connect jdbc:mysql://localhost:3306/demo_db?zeroDateTimeBehavior=CONVERT_TO_NULL \ --username root \ --password mysqlrootpassword \ --autoreset-to-one-mapper \ --warehouse-dir all_table_importNote: "--autoreset-to-one-mapper" attribute is used while importing all tables so that import will not fail when it encounter tables with no primary key.
sqoop import-all-tables \ --connect jdbc:mysql://localhost:3306/retail_db?zeroDateTimeBehavior=CONVERT_TO_NULL \ --username root \ --password mysqlrootpassword \ --autoreset-to-one-mapper \ --warehouse-dir all_table_import1 \ --exclude-tables "order_items_wp,orders_sqoop,orders_new,orders,orders_wp"
sqoop codegen \ --connect jdbc:mysql://localhost:3306/demo_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table order_items