Java - MySQL to Hive Import where MySQL Running on Windows and Hive Running on Cent OS (Horton Sandbox)

后端 未结 1 695
渐次进展
渐次进展 2021-01-06 13:41

Before any Answer and Comments. I tried several option I found in Stackoverflow but end with a failure. Following are those links -

  • How can I execute Sqoop in
相关标签:
1条回答
  • 2021-01-06 14:05

    Yes you can do it via ssh. Horton Sandbox comes with ssh support pre installed. You can execute the sqoop command via ssh client on windows. Or if you want to do it programaticaly (thats what I have done in java) you have to follow this step.

    1. Download sshxcute java library : https://code.google.com/p/sshxcute/
    2. Add to the build path of your java project which contains the following java code

    import net.neoremind.sshxcute.core.SSHExec;
    import net.neoremind.sshxcute.core.ConnBean;
    import net.neoremind.sshxcute.task.CustomTask;
    import net.neoremind.sshxcute.task.impl.ExecCommand;
    
    public class TestSSH {
    
    public static void main(String args[]) throws Exception{
    
        // Initialize a ConnBean object, parameter list is ip, username, password
    
        ConnBean cb = new ConnBean("192.168.56.102", "root","hadoop");
    
        // Put the ConnBean instance as parameter for SSHExec static method getInstance(ConnBean) to retrieve a singleton SSHExec instance
        SSHExec ssh = SSHExec.getInstance(cb);          
        // Connect to server
        ssh.connect();
        CustomTask sampleTask1 = new ExecCommand("echo $SSH_CLIENT"); // Print Your Client IP By which you connected to ssh server on Horton Sandbox
        System.out.println(ssh.exec(sampleTask1));
        CustomTask sampleTask2 = new ExecCommand("sqoop import --connect jdbc:mysql://192.168.56.101:3316/mysql_db_name --username=mysql_user --password=mysql_pwd --table mysql_table_name --hive-import -m 1 -- --schema default");
        ssh.exec(sampleTask2);
        ssh.disconnect();   
    }
    }
    

    0 讨论(0)
提交回复
热议问题