【MySql】数据库连接异常:The last packet sent successfully to the server was 0 milliseconds ago

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/b376924098/article/details/78252734

使用数据库浏览工具 或 程序 连接mysql数据库遇到异常:

The last packet sent successfully to the server was 0 milliseconds ago

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(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2196)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2229)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at com.ad.MysqlDemo.main(MysqlDemo.java:32)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.connect0(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
	... 15 more
Exception in thread "main" java.lang.NullPointerException
	at com.ad.MysqlDemo.main(MysqlDemo.java:57)


请检查核对:

1·修改my.ini bind-address = 127.0.0.1 为 bind-address = 0.0.0.0   使非本地网络可以访问数据库

2·检查防火墙是否有开放3306端口

3·网上广为流传的86400秒超时 回收机制 并不和我遇到的问题一致,这种问题是在程序运行过程中因为我们使用的连接池不知道连接被回收了所以报出的异常,解决方案可以是修改连接池配置或修改mysql空闲超时时间配置。



The last packet sent successfully to the server was 0 milliseconds ago. The driv

02-25

在本地写好的程序,发到服务器上数据库连接失败;rnlinux+mysqlrn[b]出错信息[/b]rnThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)rn at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)rn at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)rn at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)rn at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)rn at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:412)rn at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:375)rn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:913)rn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:905)rn at com.harmony.dao.common.impl.CommonDaoImpl.getMedias(CommonDaoImpl.java:29)rn at com.harmony.service.common.CommonService.getMedias(CommonService.java:19)rn at com.harmony.controller.common.CommonContraller.getMedia(CommonContraller.java:36)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:744)rnCaused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failurernrnThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)rn at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)rn at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)rn at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)rn at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:83)rn at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)rn at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)rn at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)rn at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)rn at org.hibernate.loader.Loader.doQuery(Loader.java:673)rn at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)rn at org.hibernate.loader.Loader.doList(Loader.java:2213)rn at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)rn at org.hibernate.loader.Loader.list(Loader.java:2099)rn at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)rn at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)rn at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)rn at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:922)rn at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:913)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:407)rn ... 43 morernCaused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failurern[b]数据源配置[/b]rnrn rn rn rn rn rnrn在网上找解决方法,试着更改my.cnf,没有用,大神解决一下

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭