当前位置:网站首页>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. !
边栏推荐
- Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle
- . Net module and assembly - NET Module vs Assembly
- Cypress 88359 WL command enable hotspot
- Go quick start of go language (I): the first go program
- Go language advantages and learning Roadmap
- What is the difference between a database unique index and a common index?
- sonarqube平台基础使用
- Three ways of reflection
- Will your company choose to develop data center?
- 最长递增子序列
猜你喜欢

msg=SolrCore ‘collection1‘ is not available due to init failure: Could not l

Hqchart nailing applet tutorial 1- create a K-line diagram

Arduino Uno接JQ8900-16p语音播报模块

In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May
![[big guy show] aiops in the eyes of Borui data, choosing the right track and the right people](/img/a6/61d125326fc81532a56858c384460f.jpg)
[big guy show] aiops in the eyes of Borui data, choosing the right track and the right people

How to state clearly and concisely the product requirements?

Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle

TCP/IP

Rs232/rs485 to 4G DTU uploading temperature and humidity sensor data based on Modbus protocol to remote TCP server

Application of the remote acquisition IOT gateway of the Bashir trough flowmeter in open channel flow monitoring
随机推荐
TCP/IP
B_ QuRT_ User_ Guide(19)
Will your company choose to develop data center?
Go 语言的优势和学习路线图
Whether the outbound sequence is the inbound sequence
The two departments jointly issued the nine provisions on fire safety management of off campus training institutions
VMware虚拟机IP,网关设置。虚拟机ping不通外网
Android P SoftAP start process
HQChart钉钉小程序教程1-创建K线图
OpenJudge NOI 1.13 18:Tomorrow never knows?
Deep parsing of question mark expressions
最长递增子序列
【云原生】什么是微服务?怎么搭建?手把手教你搭建第一个微服务(框架)
File file = new file ("test.txt") file path
postgresql源码学习(22)—— 故障恢复③-事务日志的注册
20220610 Friday
If you understand the logic of mining and carbon neutrality, you will understand the 100 billion market of driverless mining areas
Flink开发环境搭建及WordCount
Shell 按行读取文件
UBIFS FAQ and HOWTO