Rishi
Rishi

Reputation: 1060

How to import MySql table into a targeted database in hive?

I am using hadoop version 2.6.0 & sqoop version 1.4.5. I have successfully imported a SQL table- tblSystem into hive using the following sqoop command:

sqoop import --connect jdbc:mysql://ip_Address:port_no/MySQL_database_name --username user --password passwd --table tblSystem -m 1 --hive-import

However, I noticed that this command imports the SQL table into the 'default' database in hive. What is the command to target the import to a particular hive database, say, myHiveImport ?

Thanks in advance...

Upvotes: 1

Views: 2633

Answers (1)

Rajesh N
Rajesh N

Reputation: 2574

Import a MySQL table into Hive:

sqoop import --connect jdbc:mysql://localhost:3306/mysqldatabase --table mysqltablename --username mysqlusername --password mysqlpassword --hive-import --hive-table hivedatabase.hivetablename --warehouse-dir /user/hive/warehouse

Changes to be made:

mysqldatabase -- Your mysql database name from which the table is to be imported to hive.

mysqltablename -- Your mysql table name to be imported

mysqlusername and mysqlpassword -- mysql username and password respectively.

hivedatabase -- Your hive database name

hivetablename -- Table name to be created in hive.

Try this:

sqoop import --connect jdbc:mysql://ip_Address:port_no/MySQL_database_name --username user --password passwd --table tblSystem -m 1 --hive-import --hive-table myHiveImport.tblSystem --warehouse-dir /user/hive/warehouse

Change --warehouse-dir location to point to your HDFS hive storage path.

Upvotes: 3

Related Questions