Unable to connect remotely after ubuntu restarts MySQL

idea error:

### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: 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.] with root cause

java.net.ConnectException: Connection refused: connect

Navicat reported an error:

2003-cant connection to mysql server on ‘xx.xxx.xxx.xx’(10061 unknown error)

Solution process:

At the beginning, the plan was to modify the max_allowed_packet setting of msql, and restart MySQL after the modification. As a result, the browser interface reported a 502 error, thinking that the server port 3306 was occupied, and checked the port display. Then run MySQL locally on the server and found that it can run normally. The MySQL service was fine. Later, when I debugged the idea locally, the above error was reported, and the connection to the database failed. I guessed that it might be a problem with the remote connection. To confirm the conjecture, I opened navicat to test the remote connection. The result also reported the error above, indicating that it was indeed a remote connection. question. So Baidu read the error report of navicat, followed the solution of the reference article below to check it, and solved it successfully.

Solution:

Check whether there is a bind-address option in the configuration file. If the value of this option is 127.0.0.1, then change the value to local IP or 0.0.0.0 or comment this line.

root cause:

Why has it been fine for the past few months, but it started to report errors after restarting?

bind-address is used by MySQL to monitor a single TCP/IP connection. It can only bind one IP address. The bound IP address can map multiple network interfaces, which can be IPv4, IPv6 or hostname, but it needs to Specify when MySQL starts (the host name is resolved into an IP address for binding when the service starts).

parameter

Application Scenario
* Receive all IPv4 or IPv6 connection requests
0.0.0.0 Accept all IPv4 addresses
:: Accept all IPv4 or IPv6 addresses
IPv4-mapped Accepts all IPv4 addresses or addresses in the IPv4 binding format (e.g. ::ffff:127.0.0.1)
IPv4(IPv6) Only accept corresponding IPv4 (IPv6) addresses

Reference article:

MySQL remote connection error 2003-cant connection to mysql server on 'IP' (10061 unknown error)_zsk_john's blog-CSDN blog_mysql remote connection 2003

Guess you like

Origin blog.csdn.net/bDreamer/article/details/125166942