栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

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

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
 
            mysql
            mysql-connector-java
            8.0.27

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'" +
                " )";
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/746251.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号