FlinkSql连接Mysql出现com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failur

FlinkSql连接Mysql出现com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.The last packet successfully received from the server was 23 milliseconds ago. The last packet sent successfully to the server was 15 milliseconds ago.

Caused by: java.lang.IllegalArgumentException: open() failed.Communications link failure
The last packet successfully received from the server was 23 milliseconds ago. The last packet sent successfully to the server was 15 milliseconds ago.

at org.apache.flink.connector.jdbc.JdbcInputFormat.openInputFormat(JdbcInputFormat.java:167)
at org.apache.flink.streaming.api.functions.source.InputFormatSourceFunction.run(InputFormatSourceFunction.java:79)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:110)
at org.apache.flink.streaming.api.operators.StreamSource.run(StreamSource.java:66)
at org.apache.flink.streaming.runtime.tasks.SourceStreamTask$LegacySourceFunctionThread.run(SourceStreamTask.java:241)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 23 milliseconds ago. The last packet sent successfully to the server was 15 milliseconds ago.

在这里插入图片描述

原因:可能是账号、密码、url、driver错误
博主的原因是:Mysql版本是5.7,而Mysql的Connector使用了Mysql-5.1.44,但出现错误。
# Mysql
Mysql 5.7
# jar
mysql-connector-java-5.1.44.jar
# Driver
com.mysql.jdbc.Driver
# url
jdbc:mysql://192.168.88.101:3306/test

解决办法:使用Mysql 6以上的jar驱动(并加上时区

pom
 <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
</dependency>
code
String sql = "CREATE TABLE flink_table (id string) " +
                "WITH (" +
                "'connector.type' = 'jdbc'," +
                "'connector.url' = 'jdbc:mysql://192.168.88.101:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8'," +
                "'connector.driver' = 'com.mysql.cj.jdbc.Driver'," +
                "'connector.table' = 'test'," +
                " 'connector.username' = 'root'," +
                " 'connector.password' = '123456'" +
                " )";
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值