How to encrypt sqoop password

In this section you will learn how to enrypt sqoop password. in sqoop command we provide --password parameter with password and this is not secure and we cant use it into production. so we will use password encryption how we will see.

We can use following options

1 - Basic sqoop import command in which we will use --password with value

               
sqoop  import   --connect jdbc:mysql://localhost:3306/sqoop --username demo --password demo@123 --table emp --m 1
                
               

2 - Basic sqoop import command in which we will use -P it will prompt password and we need to enter value manually

               
sqoop  import   --connect jdbc:mysql://localhost:3306/sqoop --username demo -P --table emp --m 1
                
               

3 - Basic sqoop import command in which we will use password file

               
vi sqoop.pwd — Enter the password and save it
hadoop fs –put sqoop.pwd /user/demo/sqoop.pwd
                
               
use following command for import
               

sqoop import --connect jdbc:mysql://localhost:3306/sqoop --username demo --password-file /user/demo/sqoop.pwd --table emp --target-dir /sqoop_output/emp --m 1
                
               
Above all options are not safe enough so we have one more option for password encryption

4 - Production use

create credentials
               
hadoop credential create mydb.password.alias -provider jceks://hdfs/user/hive/mysql.password.jceks

Enter password:
Enter password again:



       
                
               
Add a property
               
-Dhadoop.security.credential.provider.path = jceks://hdfs/user/hive/mysql.password.jceks 

       
                
               
Import data from Mysql to hdfs
               
sqoop import -Dhadoop.security.credential.provider.path=jceks://hdfs/user/hive/mysql.password.jceks --connect dbc:mysql://localhost:3306/sqoop --target-dir /sqoop_output/emp --username demo --table emp --m 1