旅人杰
2021-03-09 14:27
采纳率: 50%
浏览 3.0k
已采纳

求解决困扰几天了:数据库连接超时: Connection timed out: connect

报错信息:Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

 

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:903) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.23.jar:8.0.23]
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.16.jar:1.1.16]
	at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.16.jar:1.1.16]
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.16.jar:1.1.16]
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1598) ~[druid-1.1.16.jar:1.1.16]
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1662) ~[druid-1.1.16.jar:1.1.16]
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2601) ~[druid-1.1.16.jar:1.1.16]
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

已确定信息:服务器Mysql版本:8.0.23,项目mysql-connecter..版本:8.0.23

                     mysql过期时间已经已经设为最大:wait_timeout | 31536000;interactive_timeout | 31536000

                     navicat连接数据库正常,端口开放,防火墙关闭

 

 

求求怎么解决,困扰几天了

 

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

13条回答 默认 最新

  • 三岁丫 2021-03-09 14:42
    已采纳

    你写个简单的 demo,然后连一下这个数据库试试呢,就用 DriverManager.getConnection(url, username, password) 试试。先看看是环境还问题,还是其他问题

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(12条)

相关推荐 更多相似问题