macOS ◆ xterm-256color ◆ zsh 7813 views

# 首先,检查 MySQL 和 TSDB 是否正常运行
mysql --version
curl http://localhost:8242/api/version

# 确认版本是否支持
# MySQL 只保证 5.x 是兼容的
# TSDB 只保证 2.4.x 及以上版本是兼容的

# 下载
cd /tmp/datax
wget https://tsdbtools.oss-cn-hangzhou.aliyuncs.com/datax_mysql_2_tsdb.tar.gz
tar zxvf datax_mysql_2_tsdb.tar.gz

# 配置任务
cd /tmp/datax
cp datax/job/job.json mysql2tsdb.json
{
  "job": {
    "content": [
      {
        "reader": {
          "name": "mysqlreader",
          "parameter": {
            "column": [
              "name",
              "type",
              "create_time",
              "price"
            ],
            "connection": [
              {
                "jdbcUrl": [
                  "jdbc:mysql://127.0.0.1:3306/datax"
                ],
                "table": [
                  "book"
                ]
              }
            ],
            "password": "yuzhouwan",
            "splitPk": "id",
            "username": "root"
          }
        },
        "writer": {
          "name": "tsdbwriter",
          "parameter": {
            "column": [
              "name",
              "type",
              "create_time",
              "price"
            ],
            "columnType": [
              "tag",
              "tag",
              "timestamp",
              "metric_num"
            ],
            "sourceDbType": "RDB",
            "tsdbAddress": "localhost",
            "tsdbPort": 8242
          }
        }
      }
    ],
    "setting": {
      "speed": {
        "channel": 1
      }
    }
  }
}

# 启动之前,确认 MySQL 存在数据,而 TSDB 不存在数据
# MySQL
echo "use datax; select * from book;" | mysql -u root -p

# TSDB
curl -X POST -H "Content-Type: application/json " localhost:8240/api/query -d '{"start":1556527068,"end":1556527070,"queries":[{"aggregator":"none","metric":"price"}]}'


# 通过 datax.py 脚本启动任务
python datax/bin/datax.py mysql2tsdb.json
# 任务已完成
# 现在,我们来检查是否写入成功
# MySQL
echo "use datax; select * from book;" | mysql -u root -p
# TSDB
curl -X POST -H "Content-Type: application/json " localhost:8242/api/query -d '{"start":1556527068,"end":1556527070,"queries":[{"aggregator":"none","metric":"price"}]}'

# 恭喜!
# 数据已成功迁移!