springboot 2.0.5 +mysql5.7 +druid ,本地开发测试正常,放到生产就报错 5C

**

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@17b8c0a6] was not registered for synchronization because synchronization is not active
2019-05-07 15:32:54.236 [http-nio-8081-exec-2] INFO  com.alibaba.druid.pool.DruidDataSource -{dataSource-1} inited
DruidDataSource2019-05-07 15:35:01.620 [Druid-ConnectionPool-Create-906728024] ERROR com.alibaba.druid.pool.DruidDataSource -create connection SQLException, url: jdbc:mysql://169.251.179.213:3306/bbbc?useSSL=true&characterEncoding=UTF-8, errorCode 0, state 08S01
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1510)
        at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1575)
        at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2450)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
        at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
        at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91)
        at com.mysql.cj.NativeSession.connect(NativeSession.java:152)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
        ... 6 common frames omitted
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)

```at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65)
        ... 9 common frames omitted**

5个回答

连接超时,先排除网络问题:
去线上机器ping 一下169.251.179.213,能ping通的话再检查一下telnet 169.251.179.213 3306,如果也没问题,那基本上就是代码的问题了。

qq_28104781
qq_28104781 回复b1198420279 最近改了一次安全组规则,修改了进入,忘了修改出去的端口了,谢谢
一年多之前 回复
b1198420279
b1198420279 回复qq_28104781: 嗯,根据你的描述,线下是没有问题的,线上又在报连接超时,所以怀疑是你线上的机器连不到数据库,在命令行执行以下命令,看看连接是不是好的
一年多之前 回复
qq_28104781
qq_28104781 ip是脱敏过的 没有问题,程序可以进入xxxController 以及 xxxServiceImpl,就是在访问数据(连接池)的时候报错
一年多之前 回复

数据库链接的问题,生产上telnet 3306端口或用mysql客户端先试一下能不能连上

建议检查:生产环境的是否可以ping通数据库。
一般云服务商的虚机在互访问时屏蔽了外网ip,都是通过内网ip进行的。169.251.179.213这是一个公网ip。

你的数据库连接是是不是使用了useSSL = true了,而你的服务端没有开启这个,可以把useSSL =true 改为useSSL =false 试试吧

生产环境的是否可以ping通数据库。
一般云服务商的虚机在互访问时屏蔽了外网ip,都是通过内网ip进行的。169.251.179.213这是一个公网ip

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问