16

I am using hadoop-1.2.1 and sqoop version is 1.4.4.

I am trying to run the following query.

sqoop import --connect jdbc:mysql://IP:3306/database_name --table clients --target-dir /data/clients --username root --password-file /sqoop.password -m 1

sqoop.password is a file which is kept on HDFS in path /sqoop.password with permission 400.

It is giving me an error

Access denied for user 'root'@'IP' (using password: YES)

Can anyone provide solution for this? Thanks in advance.

Nilesh Thakkar
  • 1,442
  • 4
  • 25
  • 36
Kanav Narula
  • 337
  • 1
  • 2
  • 11

7 Answers7

17

"\n" is being written in file when you vi the file and write the password. Better use the below approach to avoid problems

echo -n "Your_sqoop_password" > sqoop.password

Nandakishore
  • 981
  • 1
  • 9
  • 22
  • 2
    Exactly. the password should be naked, no newline. – ChuckCottrill Feb 02 '17 at 01:22
  • 1
    Or use vim as per https://stackoverflow.com/questions/1050640/vim-disable-automatic-newline-at-end-of-file#16114535, since part of the point of using a password file is to avoid the password appearing wherever command line usages appear in logs or `ps`. – Philip Adler Jan 16 '18 at 13:22
  • Perfect, this fixed my issue. – Kynrek Dec 23 '18 at 22:38
14

Not sure if you are still having this issue. The password file can be in any folder. Try the following syntax and it should work:

--password-file file:///user/root/database.password
ganeshrj
  • 141
  • 1
  • 6
  • Thanks a lot. I had the same problem and got solved with this answer. – SrinR Feb 05 '16 at 10:28
  • 1
    Thanks, and it worked for me as well. I would add that if you want it to look in hdfs, for me I had to use the following: `--password-file hdfs:///user/root/database.password` – Shanemeister Apr 20 '18 at 17:28
  • I was getting an error that the provided password file did not exist. But adding file:/// as per this answer helped me solve that error – user131476 Oct 06 '20 at 07:04
3

As per the sqoop documentation

You should save the password in a file on the users home directory with 400 permissions and specify the path to that file using the --password-file argument, and is the preferred method of entering credentials. Sqoop will then read the password from the file and pass it to the MapReduce cluster using secure means with out exposing the password in the job configuration. The file containing the password can either be on the Local FS or HDFS.

If I am running my sqoop job with root user then my password file will be in /user/root/ in HDFS

sqoop import --connect jdbc:mysql://database.example.com/employees \
    --username venkatesh --password-file /user/root/database.password

For more details you can check this

Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
3

While creating password, use echo -n option. (-n option removes all trailing spaces).
Suppose you have a password "myPassword" and you want to save it to a file sqoop.password, then follow below steps:

  1. Create password using command

    echo -n "myPassword" > sqoop.password
    
  2. Upload the file to HDFS as the file needs to be present in HDFS

    hadoop fs -put sqoop.password /user/keepMyFilesHere
    
  3. Write the scoop import command

    sqoop list-tables --connect jdbc:mysql://localhost/kpdatabase --username root --password-file /user/karanpreet.singh/sqoop.password
    

This will definitely work!

Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
KP Fingh
  • 79
  • 2
2

Check if there is any garbage character in your password file. I was getting the same issue and finally found that the file contained a \n character at the end and sqoop considered that also as a part of the password string. Try creating a password file as mentioned below and than use the password file : echo -n "root_password" > password.txt Place your password in place of root_password.

Ayub
  • 21
  • 2
  • On linux, ls -l, or wc will disclose the file size, and od -c or od -c (do you prefer character or hex output?) will show you the contents. – ChuckCottrill Nov 30 '16 at 19:51
1
  1. Verify that the user running the sqoop command is the owner of the file /sqoop.password (which has the 400 permissions set). This will ensure that the password file is readable.

  2. Make sure that the sqoop.password file does not have any extra non-printing characters at the end (for example, a newline character). One easy way to check this is to look at the size of the file. If the password is say 'sqoop', the size of the file should be 5. If it is larger, delete the sqoop.password file from HDFS, regenerate it locally and put it back on HDFS.

    The command that should report the above information pieces is:

    hadoop fs -ls /sqoop.password

Jagrut Sharma
  • 4,574
  • 3
  • 14
  • 19
0

please follow below link for all your sqoop password related doubts.

www.ericlin.me

Pala
  • 2,011
  • 3
  • 15
  • 17