[Database connection failure] The database connection error in IDEA reported [08S01] Communications link failure...the server was 0 milliseconds ago

Recently, there was an error when testing the connection pool with native spring, so I thought about taking a step back and directly using the classic jdbc (only mysql-connector-java), but I still reported the error-then I tested it in IDEA, and finally located the bug. Database connection problem.
 
To make a long story short, I think the macBigSur and mysql8.0 updates have caused many root user permissions and parameter default values. Because these problems have only recently been exposed, there are few feasible solutions on the Internet, and many detours have been taken.
 
It took two days for me to realize that the database connection failures in Navicat and IDEA are two separate errors . This article solves the latter . 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.

 
Literal translation: error code [08S01] connection failed

The last data packet successfully sent to the server was 0 milliseconds ago. The driver has not received any data packets from the server.

 
 
 

Troubleshoot

step1: Turn on the mysql service

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

 
step2: open mysql customer service

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

 
step3: Check the port number (if it is 0, congratulations on finding the problem)

mysql> show global variables like 'port';

 
 

solve

step4: Turn off the mysql service

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

 
step5: Manually find the file in the following path in the Finder (Finder-right click-go to the folder)

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

 
step5: a higher permission to open the file, ProgramArgumentsadd this line at:

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

 
 

effect

Restart the mysql service and open the mysql client, check the port number:

Insert picture description here

Check if IDEA is successfully connected:

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46202073/article/details/113839557