---
title: "使用datax在mysql之间同步数据"
author: "hzp"
date: "2017-08-03T13:45:04Z"
tags: []
categories: ["数据库"]
slug: "datax-mysql"
draft: false
lastmod: "2017-08-03T13:45:04Z"
id: 2388156
url: "https://hzp.iteye.com/blog/2388156"
---

使用datax在mysql之间同步数据

 

详细参考

github：[https://github.com/alibaba/DataX/wiki/Quick-Start](https://github.com/alibaba/DataX/wiki/Quick-Start)

 

1\. 下载datax

wget [http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz](http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz)

 

2\. 解压、修改目录权限

```
tar zxvf datax.tar.gz
```

```
sudo chmod -R 755 datax
```

 

3\. 执行同步job

```
python datax.py ../job/job.json
```

 

4\. job格式

> ```
> {
  "job": {
    "content": [
      {
        "reader": {
          "name": "mysqlreader",
          "parameter": {
            "column": ["id_", "topic_id_", "speak_id_", "file_id_"],
            "connection": [
              {
                "jdbcUrl": ["jdbc:mysql://*.*.*.*:3306/a?useUnicode=true&characterEncoding=UTF-8"],
                "table": ["a"]
              }
            ],
            "password": "*****",
            "username": "a",
            "where": "",
            "session": ["set names utf8mb4"]
          }
        },
        "writer": {
          "name": "mysqlwriter",
          "parameter": {
            "column": ["id_", "topic_id_", "speak_id_", "file_id_"],
            "connection": [
              {
                "jdbcUrl": "jdbc:mysql://*.*.*.*:3306/b?useUnicode=true&characterEncoding=UTF-8",
                "table": ["b"]
              }
            ],
            "password": "****",
            "username": "b",
            "where": "",
            "session": ["set names utf8mb4"]
          }
        }
      }
    ],
    "setting": {
      "speed": {
        "channel": "5"
 }
    }
  }
}
> ```