com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure
com.mysql.jdbc.exceptions.jdbc4.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.
1. Causes
Communication link failure occurs when Java connects to the database. Why can’t you log in
2 solution (my situation is invalid)
Method 1
[1] Login mysql,cmd command
mysql -h host address -u username -p user password (for example mysql -hlocalhost -uroot -p123456)
[2] Check the wait_timeout,cmd command.
show global variables like 'wait_timeout';
[3] If the wait_timeout is too small, modify it. cmd command:
set global wait_timeout=604800;
set global interactive_timeout=604800;
Method 2
Add the following parameter to the connection URL: &autoReconnect=true
3. Troubleshooting of other causes
If the above two methods are not solved, check whether there are problems in the server environment and database port.
After investigation, if the database port passes through nginx reverse proxy, or if the database port performs proxy operations through other servers, it is caused by nginx reverse proxy timeout that the database cannot be connected
You need to modify the configuration file of nginx and use steam agent Mysl
stream {
upstream mysql {
zone myapp1 64k;
server localhost:3306 weight=1 max_fails=3 fail_timeout=30s;
}
server {
listen 10086;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass mysql;
}
}
In other cases, you can also check whether the MySQL port has been proxy
Read More:
- [Solved] Druid connection pooling Error: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- [Solved] MYSQL Connect Error: Communications link failure
- CommunicationsException: Communications link failure [How to Solve]
- (Fixed) workbench MySQL Error Code: 2013. Lost connection to MySQL server during query
- IDEA maven Config MYSQL Connection Error: Could not create connection to database server.
- C# Connect MYSQL Error: MySql.Data.MySqlClient.MySqlException:“SSL Connection error.”
- Remote connection to MySQL database error: is not allowed to connect to this MYSQL server solution
- C# connection MySQL error: SSL connection error [Solved]
- MySQL (version 8.0) connection error: 1251 [How to Solve]
- [Solved] docker mysql SQLSTATE[HY000] [2002] Connection refused
- Sqlyog connection MySQL error: 2003 [How to Solve]
- [Solved] Error Code: 2013. Lost connection to MySQL server during query
- [Solved] There is a problem with mysql8.0 without password in Navicat connection
- [Solved] com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
- Android connection to cloud MySQL error: java.lang.NoClassDefFoundError Failed resolution of LjavasqlSQLType
- Docker: How to Solve MYSQL8 & Navicat remote connection error
- [Solved] Navicat connection error 1251 compatibility with docker MySQL
- [Solved] SQLSTATE[HY000] [2002] Connection refused to report an error when PHP connects to mysql in the docker container
- Mysql Flashback Warning: C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe
- [Solved] ERROR 2002 (HY000): Can’t connect to local MySQL server through socket’/var/lib/mysql/mysql.sock’ (2)