如何将MySQL数据导入Hadoop文件系统?

时间:2015-12-03 09:01:21

标签: mysql hadoop2 sqoop2 sqoop

在我的系统中,我在Mysql中有数据库。我想将其导入hadoop文件系统。我发现了一些关于Sqoop的事情,但我没有得到这样做的命令。

3 个答案:

答案 0 :(得分:2)

sqoop import --connect jdbc:mysql:// mysql-server-name / db_name --username user --password password --table table_name --target-dir target_directory_name -m1

希望有所帮助......

答案 1 :(得分:0)

您需要安装mysql jdbc / java连接器并运行sqoop命令。

package mylib1;

import java.io.FileNotFoundException;
    import java.util.Scanner;


    import java.io.*;

    public class Schedule {

        public static void executeTask(int option){
            char addmore='n'; 
            switch(option){
            case 0: 
                    return; 
            case 1: 
                    do{
                        add();
                        addmore = getContinue("add");
                        if(addmore=='n')
                            break;
                    }while(true); 
                    break;
            case 2: 
                do{
                    view();
                    addmore = getContinue("view");
                    if(addmore=='n')
                        break;
                }while(true); 
                break;
            }
        }
         public static char getContinue(String methodName){
             char ch='n'; 
             try{
                    System.out.println("Do you want to " +methodName + " more records (y/n)?"); 
                    ch = (char) System.in.read();

                }catch(IOException e){
                    System.out.println("IOException in input....");
                }
             return ch;
         }
        public static void add() {
            char ch; 
            System.out.println("Add Record");
            System.out.println("---------------");
            System.out.println();
            File file = new File("readcoursefile.txt");

                try {

                    Scanner scanner = new Scanner(file);

                    while (scanner.hasNextLine()) {
                        String line = scanner.nextLine();
                        System.out.println(line);
                    }
                    scanner.close();
                } catch (FileNotFoundException e) {
                    System.out.println("file not found");
                }

            try{
                System.out.println("Do you want to save/cancel record s/c"); 
                ch = (char) System.in.read();

            }catch(IOException e){
                System.out.println("IOException in input....");
            }



        }

        public static void update(){
            System.out.println("Update Record");
            System.out.println("---------------");
            System.out.println();


        }

        public static void view(){
            System.out.println("View Record");
            System.out.println("---------------");
            System.out.println();



        }

        public static void delete(){
            System.out.println("Delete Record");
            System.out.println("---------------");
            System.out.println();

            //prompt user for console input (attributes)

            //write/update user record from file.

        }

        public static void search(){
            System.out.println("Search Record");
            System.out.println("---------------");
            System.out.println();



        }



    }

您可以从中运行sqoop命令 Save data into mysql from hive hadoop through sqoop?

答案 2 :(得分:0)

1)安装&首先配置MySQL。在MySQL中创建数据库

2)sqoop import --connect jdbc:mysql://localhost/databasename --username $USER_NAME --password $PASSWORD$ --table tablename --m 1命令将导入数据。

e.g。

sqoop import --connect jdbc:mysql:// localhost / testDb --username root --password hadoop123 --table student --m 1

在上述命令中,各种参数的值database:‘testDb’username: ‘root’password: ‘hadoop123’table student

请仔细查看此article 1article 2,以便逐步了解