第二周--初次使用datax(mysql中兩表的數據遷移)


在cmd里進行操作:

CHCP 65001(解決亂碼)最好輸入,不然提示消息看不懂

 

1.兩個表數據:(將person中的名字和年齡數據遷移到person2中)

 

 

 

 2.查看mysql的讀寫的json格式(復制下來,在datax的job文件中新建一個json文件)

python datax.py -r mysqlreader -w mysqlwriter

 

 

 

 3.修改標准模板

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "mysqlreader",
                    "parameter": {
                        "column": ["name","age"],
                        "connection": [
                            {
                              "jdbcUrl": [ "jdbc:mysql://127.0.0.1:3306/datax" ],
                                "table": ["person"]
                            }
                        ],
                        "password": "mm123456",
                        "username": "root",
                        "where": ""
                    }
                },
                "writer": {
                    "name": "mysqlwriter",
                    "parameter": {
                        "column": ["name","age"],
                        "connection": [
                          {
                            "jdbcUrl": "jdbc:mysql://127.0.0.1:3306/datax",
                            "table": ["person2"]
                          }
                        ],
                        "password": "mm123456",
                        "preSql": [],
                        "session": [],
                        "username": "root",
                        "writeMode": "insert"
                    }
                }
            }
        ],
        "setting": {
            "speed": {
                "channel": "1"
            }
        }
    }
}

4.在回到cmd里運行json文件

 

 

python2 datax.py F:\大學學習軟件\文件壓縮包\datax\job\mysqltest.json

 

 

5.附上java運行的代碼

package datax_test;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class Dataxdemo1 {
    public static void main(String[] args) {
        try {
            
            
            String windowcmd = "cmd /c python2 datax.py F:\\大學學習軟件\\文件壓縮包\\datax\\job\\mysqltest.json";
            
            //.exec("你的命令",null,new File("datax安裝路徑"));
            Process pr = Runtime.getRuntime().exec(windowcmd,null,new File("F:\\大學學習軟件\\文件壓縮包\\datax\\bin"));
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line = null;
            while ((line = in.readLine()) != null) {
                
            }
            in.close();
            pr.waitFor();
            System.out.println("運行結束!!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM