当前位置:网站首页>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. !
边栏推荐
- Recent learning and update plan
- CPT 102_ LEC 13-14
- 出栈序列是否是入栈序列
- Log4j:error category option "1" not a decimal integer
- 配置用命令行编译的环境-MSVC
- ORA-00392 ORA-00312 错误处理
- intXX_ T and int_ fastXX_ T what is the difference- What is the difference between intXX_ t and int_ fastXX_ t?
- CPT 102_ LEC 18
- HUST软件工程(实验2)--TDD测试驱动开发实验。
- How to state clearly and concisely the product requirements?
猜你喜欢

Hough transform of image

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

How to handle error code 30204-44 when installing office 2016 in win10?

文件合成器
![[new open source project] dynamic configuration task scheduling framework gobrs async joins the dromara open source community](/img/26/2d0c4e8f7f4055e614080fe526328c.png)
[new open source project] dynamic configuration task scheduling framework gobrs async joins the dromara open source community

WinDbg virtual machine dual machine debugging driver file debugging

sonarqube平台基础使用

Detailed explanation of unity project optimization (continuous supplement)

Go language advantages and learning Roadmap

The two request sessionids of the same user are inconsistent ----- record the problem
随机推荐
ROS基础 - 使用 launch 文件(一) - 批量启动多个ROS节点
Arduino uses nRF24L01 module for wireless communication
怎样简洁明了地说清楚产品需求?
Pyqt5:qlineedit control code
Go语言之Go 快速入门篇(一):第一个 Go 程序
B / Qurt Utilisateur Guide (19)
ASLR
VMware虚拟机IP,网关设置。虚拟机ping不通外网
PIP installation Qt5.
postgresql源码学习(十七)—— MVCC②-快照与隔离级别简介
Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
Start QQ through the program to realize automatic login
Shell 按行读取文件
Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle
Discussion on the concurrency security of a common set on players
A simple understanding of C language array
TimeHelper
@Controller @transactional @service annotation is invalid and less dependent
DNS Optimization Practice of APP network optimization
Pyqt5:slider slider control