thotwielder
thotwielder

Reputation: 1707

hadoop sqoop load csv file into mysql

I am learning hadoop sqoop. I am working on a hortonworks sandbox (a hadoop virtual machine of single node: http://hortonworks.com/products/hortonworks-sandbox/#install).

I am trying to load a csv file via sqoop into a mysql table. I have created a database flightinfo and a table weather in it. I created a table in hive called sqoop_tmp with the file location of that csv file.

I used following command to load the csv into mysql:

    sqoop export --connect jdbc:mysql://localhost/flightinfo –-table weather –-export-dir /apps/hive/warehouse/sqoop_tmp

Here is the error message: enter image description here

update: @z-1 I tried your code and it returns something different enter image description here

Upvotes: 2

Views: 4097

Answers (3)

Avinash Reddy
Avinash Reddy

Reputation: 1185

You have to provide username and password of MySQL and must have permissions to access the database.

It looks like you did a fresh install of mysql and didn't not configure the root account to secure with root password.

You can do that using the following steps:

  1. $ mysqladmin -u root password "newpassword" for example $ mysqladmin -u root password mysql-root-password
  2. Restart MySQL daemon. $ sudo service mysqld restart or $ sudo /etcinit.d/mysqld restart
  3. Login to MySQL using $ mysql -u root -P and enter the password when prompted.

If you have your database created as root user. Now you can issue the following sqoop command to export data from hdfs to sqoop database.

$ sqoop export --connect jdbc:mysql://localhost/flightinfo --username root -P --table weather --export-dir /apps/hive/warehouse/sqoop_tmp

Still facing permission issue?? Permission to the user to access database is the problem.

Then, You should be able to solve by granting permissions using the steps below.

  1. Login to MySQL using $ mysql -u root -P

  2. mysql> GRANT all PRIVILEGES on filghtinfo.* to 'root'@'localhost' IDENTIFIED BY 'password'

    Note: The password you set here should be used from sqoop.

Upvotes: 1

Kishore
Kishore

Reputation: 5881

try with username and password of mysql

sqoop export --connect jdbc:mysql://localhost/flightinfo --table weather --export-dir /apps/hive/warehouse/sqoop_tmp --username SomeUser -P

Note - user should have permission.

Upvotes: 1

moon
moon

Reputation: 1832

Try this:

sqoop export --connect jdbc:mysql://localhost/flightinfo --table weather --export-dir /apps/hive/warehouse/sqoop_tmp

You had –- not --. These two are not the same.

Upvotes: 0

Related Questions