Foe importing data from mysql to Hive table

Please use below basic command to import mysql table into hive.Below command will import mysql table data directly into hive and by using  --hive-import argument table table1 will be automatically created in hive.

sqoop import --connect jdbc:mysql://localhost/abhiD --username root -P --table table1 --hive-import

In above command abhiD is the database name in mysql table1 is table inside abhiD database.

Foe exporting data from Hive table to mysql


While exporting data from HDFS to mysql the target table must exist in the target database. 
Please refer below command to transfer data from hdfs to mysql 

// Data in file emp_tbl in HDFS
101, abhi, manager, 50000
102, tiwari, preader, 50000

It is mandatory that the table to be exported is created manually and is present in the database from where it has to be exported.

The following query is used to create the table ‘employee’ in mysql command line.

CREATE TABLE employee ( 
   id INT NOT NULL PRIMARY KEY, 
   name VARCHAR(20), 
   deg VARCHAR(20),
   salary INT);

The following command is used to export the table data (which is in emp_tbl file on HDFS) to the employee table

sqoop export --connect jdbc:mysql://localhost/dbName --username root -P --table employee --export-dir /user/hive/warehouse/emp_tbl

You can verify the export by running select * from employee command.



Regards,
Abhishek Tiwari
edureka! Support Team

197145