ETL工具-Kettle连接MySQL报错及解决方案

1.驱动问题

在kettle中新建mysql连接时,一般都选择Native(JDBC)方法,这时需要下载与MySQL版本对应的connector连接jar包,放在kettle安装目录的 data-integration\lib下;
低版本的MySQL数据库按这种方法一般没问题,但是mysql 8.0以上connector已经不再支持这个包名,所以会出现已经将mysql-connector-java-8.0.xx.jar包拷贝到lib目录下,但还是报错说找不到驱动。
报错如下:

错误连接数据库 [tcc] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Driver class ‘org.gjt.mm.mysql.Driver’ could not be found, make sure the ‘MySQL’ driver (jar file) is installed.

这种方法不能指定驱动类型,kettle默认使用的驱动类型是org.gjt.mm.mysql.Driver;

解决方法

这时可以采用JNDI方法设置kettle使用com.mysql.cj.jdbc.Driver作为连接MySQL的驱动。
具体设置如下:
将mysql-connector-java-8.0.xx.jar包拷贝到lib目录下,
然后在data-integration\simple-jndi目录下的jdbc.properties文件中新建JNDI配置:

注意:代码中的中文部分改成你要连接的MySQL数据库相关配置

mysql_test/type=javax.sql.DataSource
mysql_test/driver=com.mysql.cj.jdbc.Driver
mysql_test/url=jdbc:mysql://填写你的主机名:3306/填写你的数据库名?useUnicode=true&characterEncoding=utf-8&disableMariaDbDriver
mysql_test/user=填上你的MySQL数据库登录用户名
mysql_test/password=填上你的MySQL数据库登录密码

原文链接:https://blog.csdn.net/zougen/article/details/84975410

2.时区冲突问题

按照上述方法设置后一般能正常连接,但是有些也会报如下错误:

java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or represents more than one time zone.
You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解决方法

MySQL连接地址加个配置: &serverTimezone=UTC
还是上述data-integration\simple-jndi目录下的jdbc.properties文件中:
– 原来的设置

-- 原来的设置
mysql_test/url=jdbc:mysql://填写你的主机名:3306/填写你的数据库名?useUnicode=true&characterEncoding=utf-8&disableMariaDbDriver

– 修改后的设置

-- 修改后的设置
mysql_test/url=jdbc:mysql://填写你的主机名:3306/填写你的数据库名?useUnicode=true&characterEncoding=utf-8&disableMariaDbDriver&serverTimezone=UTC

猜你喜欢

转载自blog.csdn.net/Artificial_idiots/article/details/106977622