Enrollments Open for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee

  Apply Now

Sqoop Export - Hive to MySQL

Prepare Source

# Copy sales.log locally 
hadoop fs -copyToLocal /data/hive/sales.log

# Launch hive using the command: hive

# Please use your own database
use sg;

# Create Hive Table:

CREATE TABLE sales_test(widget_id INT, qty INT,
street STRING, city STRING, state STRING,
zip INT, sale_date STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

# Find the location of your table using:
describe formatted sales_test;
# Load Data:
LOAD DATA LOCAL INPATH "sales.log" INTO TABLE sales_test;
# Select rows to see data:
select * from sales_test;

Prepare MySQL Table

#TO launch mysql:
    mysql -h cxln2.c.thelab-240901.internal -u sqoopuser -pNHkkP876rp

#Create MYSQL Table:
use sqoopex;
CREATE TABLE sales_sgiri(widget_id INT, qty INT, street varchar(100), city varchar(100), state varchar(100),
zip INT, sale_date varchar(100));

Sqoop Export - Hive To MySQL

# Sqoop Export: using your own database and table
sqoop export --connect jdbc:mysql://cxln2.c.thelab-240901.internal/sqoopex -m 1 --table sales_sgiri --export-dir /apps/hive/warehouse/sg.db/sales_test --input-fields-terminated-by ',' --username sqoopuser --password NHkkP876rp;

# Go back to the MySQL prompt and check
use sqoopex;
select * from sales_sgiri;


No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...