主机迷主机迷

SpringBoot连接MySQL5.7报错org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution

SpringBoot应用连接MySQL5.7,启动报错:org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution。

Caused by: org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:112)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
...
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
...

原因是在小内存vps上为了减少MySQL的内存占用,增加了一些设置,里面有个skip-networking,这个导致jdbc连接不了MySQL,去掉就好了。
随后又发现有的php应用不受skip-networking的影响。比较不同php应用的连接MySQL的配置,发现使用127.0.0.1连接MySQL受影响,而使用localhost连接MySQL可以正常连接。
总结,要解决此问题,要么去掉skip-networking,要么把连接字符串由127.0.0.1改为localhost。

转载请注明出处 | 当前页面:主机迷 » SpringBoot连接MySQL5.7报错org.hibernate.exception.JDBCConnectionException: Unable to open JDBC Connection for DDL execution

评论

  • 请输入 2 + 1 = ? 的计算结果: