当前位置:网站首页>已解决: JDBC连接Mysql失败报错: 'The last packet sent successfully to the server was 0 milliseconds ago. '
已解决: JDBC连接Mysql失败报错: 'The last packet sent successfully to the server was 0 milliseconds ago. '
2022-06-11 02:40:00 【CSDN问答】
第一次尝试JDBC连接Mysql, 然后一直报错。
报错代码:
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 more运行结果及报错内容
尝试过修改时区、字符集、wait_timeout之类的,但是没有效果。然后驱动使用的是:“mysql-connector-java-8.0.17.jar”, mysql也是8.0版本以上的, 匹配应该没有问题。
url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&userUnicode=true&charsetEncoding=utf-8url=jdbc:mysql://localhost:3306/testdriverClass=com.mysql.cj.jdbc.Driver希望可以帮忙看看, 正在学习JDBC,但是第一步连接失败。
后来遇到的问题:
- ping不通3306
开始mysql之后,连接仍然失败。sudo /usr/local/mysql/support-files/mysql.server startStarting MySQLSUCCESS!
打开Navicat又发现: Can't connect to local server through socket '/tmp/mysql.sock' (2)
等等。 就是一系列的问题, 于是决定今天卸载mysql。
通过命令行无法删除mysql后,我直接在系统偏好设置的Mysql下选择uninstall。 然后在官网https://downloads.mysql.com/archives/community/
下载了符合电脑版本的dmg文件,直接安装。 选择的是Strong password, 之前选择的是legacy password(就是旧的方法). 之前第一次下载mysql后,尝试在Navicat上建立mysql连接经常失败, 后来勾选了使用套文件又把主机的位置那里写成“127.0.0.1”, 连接名写成"localhost"才成功。
现在卸载后重新安装后,竟然JDBC连接mysql成功了!谢谢大家!
边栏推荐
- 基于互联网架构演进, 构建秒杀系统
- Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
- Navicat premium 15 tool is automatically deleted by anti-virus protection software solution
- 2022年熔化焊接与热切割操作证考试题库及答案
- OpenJudge NOI 1.13 17:文字排版
- [resolved] how to fix another update in progress WordPress upgrade error
- Determine whether a string of numbers is the result of a quick sort
- Correct posture of cocoscreator's native secondary development
- Arduino uno connected to jq8900-16p voice broadcast module
- Manon's advanced road - Daily anecdotes
猜你喜欢

Arduino uses nRF24L01 module for wireless communication

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

Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
![[189. rotation array]](/img/cc/0da616ad9adc9c9d352e54f58dbe41.png)
[189. rotation array]
![[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

VMware虚拟机IP,网关设置。虚拟机ping不通外网

pip 安装 qt5 。

How to state clearly and concisely the product requirements?

HUST Software Engineering (Experiment 2) -- TDD test driven development experiment.
![[C language classic]: inverted string](/img/f3/e6f37b852d22d395314628b73c9be3.jpg)
[C language classic]: inverted string
随机推荐
Forest v1.5.22 release! Kotlin support
Three ways of reflection
牛客网:数组中只出现一次的两个数字
Manon's advanced road - Daily anecdotes
[big guy show] aiops in the eyes of Borui data, choosing the right track and the right people
判断一串数字是否是快速排序某一次的结果
GraphAcademy 课程讲解:《Neo4j 图数据科学基础》
HUST软件工程(实验2)--TDD测试驱动开发实验。
How to handle error code 30204-44 when installing office 2016 in win10?
Three special data types, day3 and redis (geographic location, cardinality statistics and bitmap scene usage)
Flink开发环境搭建及WordCount
求MySQL先按大于等于当前时间升序排序,再按小于当前时间降序排序
Net core Tianma XingKong series - Interface Implementation for dependency injection and mutual conversion of database tables and C entity classes
Application of the remote acquisition IOT gateway of the Bashir trough flowmeter in open channel flow monitoring
net core天马行空系列-可用于依赖注入的,数据库表和c#实体类互相转换的接口实现
AOSP ~ Logcat Chatty 行过期
CocosCreator原生二次开发的正确姿势
【大咖秀】博睿数据眼中的AIOps,选择正确的赛道正确的人
Cmake common commands
Fuluo classic source code Fuluo classic system development principle sharing