Search code examples
mysqlhadoopsqoopbigdata

How to export data from Hadoop to MySQL /any DB?


Most of tutorials I've researched point me that I have to use Sqoop for export/import and a lot of the manuals show how I can export data from DB to HDFS, but how I can do backwards case?

Let's say, I have company DB on localhost, it has an empty users table with columns: id, user and I have hadoop that provides me with data like (id, user) but saves this to some hadoop-output.txt not to MySQL.

Are there some commands for command line to make import from HDFS to MySQL via Sqoop?


Solution

  • sqoop-export does this.

    sqoop-export --connect jdbc:mysql://localhost/company 
                 --username user --password passwd 
                 --table users 
                 --export-dir /path/to/HDFS_Source
                 --input-fields-terminated-by ','
    

    Refer SqoopUserGuide.html#sqoop_export