datax从oracle到mysql数据传输

发布时间 2023-10-18 20:53:00作者: 醉不在意

datax进行数据迁移: 

所需配置:1、服务器:windows/linux(本人使用的本地windows)

                  2、环境:python2.6.3   和java.11.0.20(本人使用)

                  3、datax(https://github.com/taosdata/DataX

以上下载完成后可以通过下面命令来查看是否下载成功:

java -version(查看java版本)

python -V(查看python版本

下载完成datax后进入bin目录下打开命令行执行:python D:\datax\bin\datax.py  D:\datax\job\job.json

说明:

Python:执行pytho的
D:\xx.py:datax的py脚本
D:\xx.json:同步配置的json文件
如果出现乱码的话,在CMD中输入:
CHCP 65001
 

获取reader/writer模板 :python datax.py -r streamreader -w streamwriter   

   

 

上述模板填完后可执行文件:

执行命令:python datax.py stream.json

执行过程中可能出现的错误及解决办法:

错误1:对于readername : oraclereader

2023-10-18 14:37:15.374 [job-0] WARN DBUtil - test connection of [jdbc:oracle:localhost:port/服务名] failed, for Code:[DBUtilErrorCode-10], Description:[连接数据库失败. 请检查您的 账号、密码、数据库名称、IP、Port或者向 DBA 寻求帮助(注意网络环境).]. - 具体错误信息为:java.sql.SQLException: 指定了无效的 Oracle URL.
2023-10-18 14:37:15.376 [job-0] ERROR RetryUtil - Exception when calling callable, 异常Msg:DataX无法连接对应的数据库,可能原因是:1) 配置的ip/port/database/jdbc错误,无法连接。2) 配置的username/password错误, 鉴权失败。请和DBA确认该数据库的连接信息是否正确。

解决办法:jdbcurl格式: 使用thin方法

                                          "jdbc:oracle:thin:@localhost:port/服务名"

 

错误2:对于writername  : mysqlwriter 

2023-10-18 14:47:41.918 [job-0] ERROR RetryUtil - Exception when calling callable, 异常Msg:Code:[DBUtilErrorCode-10], Description:[连接数据库失败. 请检查您的 账号、密码、数据库名称、IP、Port或者向 DBA 寻求帮助(注意网络环境).].  -  具体错误信息为:java.sql.SQLException: No suitable driver found for jdbc:mysql:localhost:port/db_name?characterEncoding=utf8&yearIsDateType=false&zeroDateTimeBehavior=convertToNull&tinyInt1isBit=false&rewriteBatchedStatements=true

解决办法 : jdbcurl 格式:jdbc:mysql://localhost:port/db_name?characterEncoding=utf8

 

错误3:对于writername  : mysqlwriter  

2023-10-18 14:43:13.583 [job-0] ERROR RetryUtil - Exception when calling callable, 异常Msg:Code:[DBUtilErrorCode-10], Description:[连接数据库失败. 请检查您的 账号、密码、数据库名称、IP、Port或者向 DBA 寻求帮助(注意网络环境).]. - 具体错误信息为:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
解决办法:1.下面jdbcUrl只能指定一个路径,将列表转为字符串即可 []换成 ""

                     "jdbcUrl":["jdbc:mysql://localhost:3306/temp?characterEncoding=utf8"]改为
                     "jdbcUrl":"jdbc:mysql://localhost:3306/temp?characterEncoding=utf8"
                  2.原因:电脑上的mysql版本高,而项目中的mysql-java驱动版本过低,二者不匹配。

                     解决步骤:1、mysql>select version(); 查看mqsql版本,我的版本是8.0.29

                                       2、去官网下载对应版本的mysql-java驱动,MySQL :: Download MySQL Connector/J (Archived Versions)

                                  

 

                                             下载完后解压文件,用mysql-connector-java-8.xxx.jar替换原来的mysql-connector-java-5.xxx.jar(直接换到datax/plugin/writer/mysqlwriter/libs目录下)

                                              替换完成后运行 python datax.py 路径/stream.json                            

                                              jdbcurl=jdbc:mysql://localhost:3306/xxxxxx 末尾加上&serverTimezone=UTC

                                              username和password跟你本机数据库用户名/密码一致

                                            (driver改成com.mysql.cj.jdbc.Driver(mysql 5.xxx 这里的驱动类是com.mysql.jdbc.Driver))