当前位置:网站首页>Resolved: JDBC connection to MySQL failed with an error:'The last packet sent successfully to the server was 0 milliseconds ago. '
Resolved: JDBC connection to MySQL failed with an error:'The last packet sent successfully to the server was 0 milliseconds ago. '
2022-06-11 03:08:00 【CSDN Q & A】
First attempt JDBC Connect Mysql, And then keep reporting the error .
Error code :
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failureThe 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:172) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) at connection.connectionTest.connectionTest1(connectionTest.java:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failureThe 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:59) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:103) at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:149) at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:165) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:92) at com.mysql.cj.NativeSession.connect(NativeSession.java:152) at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:982) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852) ... 26 moreCaused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394) at java.net.Socket.connect(Socket.java:606) at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:173) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:66) ... 29 moreOperation results and error reporting contents
Tried to modify the time zone 、 Character set 、wait_timeout And so on. , But it didn't work . Then the driver uses :“mysql-connector-java-8.0.17.jar”, mysql It's also 8.0 Version above , There should be no problem with matching .
url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&userUnicode=true&charsetEncoding=utf-8url=jdbc:mysql://localhost:3306/testdriverClass=com.mysql.cj.jdbc.DriverI hope I can help you see , Is learning JDBC, But the first step failed to connect .
Problems encountered later :
- ping no 3306
Start mysql after , The connection still failed .sudo /usr/local/mysql/support-files/mysql.server startStarting MySQLSUCCESS!
open Navicat And found out : Can't connect to local server through socket '/tmp/mysql.sock' (2)
wait . Is a series of problems , So I decided to uninstall today mysql.
Cannot delete... From the command line mysql after , I am directly in the system preferences Mysql Choose uninstall. Then on the official website https://downloads.mysql.com/archives/community/
Downloaded the computer version of dmg file , Direct installation . The choice is Strong password, The choice before was legacy password( It's the old way ). First download before mysql after , Try to Navicat On the establishment of mysql Connections often fail , Later, I checked the use set file and wrote the location of the host as “127.0.0.1”, The connection name is written as "localhost" To succeed .
Now uninstall and reinstall , actually JDBC Connect mysql succeed ! Thank you. !
边栏推荐
- Wechat template message errCode ": 40165," errmsg ":" invalid web pagepath
- Explication du cours de graphacademy: neo4j Graph Data Science Foundation
- Go 语言的优势和学习路线图
- Can Xiaoxiang life become the "Yonghui" in the discount industry after the completion of the round a financing of tens of millions of yuan?
- Whether the outbound sequence is the inbound sequence
- Hqchart actual combat tutorial 55 area map of K line of ouyi.com
- postgresql源码学习(22)—— 故障恢复③-事务日志的注册
- The new colleague asked me what "where 1=1" means???
- [big guy show] aiops in the eyes of Borui data, choosing the right track and the right people
- pip 安装 qt5 。
猜你喜欢

Error in Solr access: error initializing queryelevationcomponent

com. mchange. v2.c3p0. Combopooleddatasource red

GraphAcademy 课程讲解:《Neo4j 图数据科学基础》

Demand and Prospect of 3D GIS Industry

Live broadcast! Feature matching of orb-slam3 series (mlpnp, word bag model, etc.).

Operations on annotation and reflection

postgresql源码学习(二十)—— 故障恢复①-事务日志格式

Explication du cours de graphacademy: neo4j Graph Data Science Foundation

第七章 常用的协议简介(1)

B_QuRT_User_Guide(18)
随机推荐
【云原生】什么是微服务?怎么搭建?手把手教你搭建第一个微服务(框架)
How to state clearly and concisely the product requirements?
Solr initialization failure: requesthandler INIT failure
2022年熔化焊接与热切割操作证考试题库及答案
intXX_ T and int_ fastXX_ T what is the difference- What is the difference between intXX_ t and int_ fastXX_ t?
Pyqt5:slider slider control
已解决: JDBC连接Mysql失败报错: 'The last packet sent successfully to the server was 0 milliseconds ago. '
Can Xiaoxiang life become the "Yonghui" in the discount industry after the completion of the round a financing of tens of millions of yuan?
Arduino uno connected to jq8900-16p voice broadcast module
Location data fusion Table 3
Error in Solr access: error initializing queryelevationcomponent
Pyqt5:qlineedit control code
MySQL is required to sort in ascending order greater than or equal to the current time, and then in descending order less than the current time
org. apache. solr. common. SolrException:Could not load core configuration for core hotel
20220610 Friday
Hqchart nailing applet tutorial 1- create a K-line diagram
Openjudge noi 1.13 17: text layout
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
Arduino使用NRF24L01模块进行无线通信
Arduino uses nRF24L01 module for wireless communication