Sqoop can be used to export data seamlessly from HDFS into RDBMS systems. Sqoop provides many options to handle different scenarios. Many of them will be explained in multiple tutorials with examples. This Sqoop tutorial will cover simple export, export with delimiter, export specific columns, export with update only and export with upsert.
Generic Arguments to export command
Attribute |
Description |
--export-dir |
This is used to specify HDFS directory from where data need to be exported. |
--table |
This is used to specify RDBMS table name where data need to be exported. |
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table order_items \ --export-dir hdfs://localhost:9000/user/username/retail_db/order_items
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table order_items \ --export-dir hdfs://localhost:9000/user/username/retail_db/order_items --input-fields-terminated-by "\001"
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table daily_revenue_demo \ --export-dir hdfs://localhost:9000/user/hive/warehouse/daily_revenue.db/daily_revenue_txt \ --bindir $SQOOP_HOME/lib/ \ --columns order_date,revenue
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table daily_revenue_demo \ --export-dir hdfs://localhost:9000/user/hive/warehouse/daily_revenue.db/daily_revenue_ctlr_a \ --bindir $SQOOP_HOME/lib/ \ --columns order_date,revenue \ --input-fields-terminated-by "\001"
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --driver com.mysql.cj.jdbc.Driver \ --table orders \ --export-dir hdfs://localhost:9000/user/username/retail_db/orders \ --bindir $SQOOP_HOME/lib/ \ --update-key order_id
sqoop export \ --connect jdbc:mysql://localhost:3306/retail_db \ --username root \ --password mysqlrootpassword \ --table orders \ --export-dir hdfs://localhost:9000/user/username/retail_db/orders \ --bindir $SQOOP_HOME/lib/ \ --update-key order_id \ --update-mode allowinsertNote: For upsert to work in mysql, update key should be primary key else it will insert only.