【数据库连接失败】IDEA中数据库连接报错 [08S01] Communications link failure...the server was 0 milliseconds ago解决方案

最近在用原生spring测试连接池时出现报错,便想着退一步直接使用经典的jdbc(只使用mysql-connector-java),没想到依旧报错——接着在IDEA中进行测试,最终将bug定位在数据库连接问题。
 
长话短说,我认为是macBigSur以及mysql8.0的更新,导致了众多root用户权限、参数默认值问题。因为这些问题在最近才暴露出来,网上很少有可行解决方案,走了不少弯路。
 
耗费两天时间我才后知后觉,Navicat和IDEA中的数据库连接失败是两个独立的错误,本篇解决后者。let’s go。

 
 

[08S01] 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.

 
直译:错误代码[08S01] 连接失败

上次成功发送到服务器的数据包是0毫秒以前。驱动程序还没有收到来自服务器的任何数据包。

 
 
 

排查

step1:开启mysql服务

sudo /usr/local/mysql/support-files/mysql.server start

 
step2:开启mysql客服端

sudo /usr/local/mysql/bin/mysql -u root -p

 
step3:检查端口号(如果是0,那么恭喜你找到了问题所在)

mysql> show global variables like 'port';

 
 

解决

step4:关闭mysql服务

sudo /usr/local/mysql/support-files/mysql.server stop

 
step5:在访达中手动找到下面路径的文件(访达-右键-前往文件夹)

/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist

 
step5:以较高权限打开该文件,在ProgramArguments下添加这么一行:

<string>--port=3306</string>

 
 

效果

重新开启mysql服务并打开mysql客户端,检查端口号:

在这里插入图片描述

看看IDEA是不是连接成功了:

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_46202073/article/details/113839557
今日推荐