Time for action – exporting data from MySQL into Hive
For this example, we'll export all the data from a single MySQL table into a correspondingly named table in Hive. You will need Hive installed and configured as detailed in the previous chapter.
Delete the output directory created in the previous section:
$ hadoop fs -rmr employees
You will receive the following response:
Deleted hdfs://head:9000/user/hadoop/employees
Confirm Hive doesn't already contain an employees table:
$ hive -e "show tables like 'employees'"
You will receive the following response:
OK Time taken: 2.318 seconds
Perform the Sqoop import:
$ sqoop import --connect jdbc:mysql://10.0.0.100/hadooptest --username hadoopuser -P --table employees --hive-import --hive-table employees
Check the contents in Hive:
$ hive -e "select * from employees"
You will receive the following response:
OK Alice Engineering 50000 2009-03-12 Camille Marketing 40000 2003-04-20 David Executive 75000 2001-03-20 Erica Support 34000...