Because mysql has a default connect_timeout time, once it exceeds, it will automatically close the connection.
You can try the following two ways:
- The connect_timeout time is specified when creating a connection, and the setting is longer.
- Every time you operate the database, a connection is established and closed after the operation. In the code, close the cursor in time and close the connection.
solve
Enter the command in the New Query windowshow global variables like "%timeout%";
use commandSET GLOBAL connect_timeout = 24*3600;
1. The MySQL server is really gone
We can check if the server is indeed gone by checking the server uptime (uptime) and the server's error log.
Check MySQL's uptime (uptime):show global status like "uptime";
Query the storage location of the error log, then open the error log, and check whether the server is down based on the log records.
Query the storage location of the error log:show variables like "%error";
If the MySQL server does disappear, is it down or crashed, MySQL's error log will provide the answer. Normally the MySQL daemon (mysqld) will be restarted by the mysqld_safe wrapper process.
### 2. Connection timeout
View various connection times:show global variables like "%timeout";
These values are relatively MySQL defaults, but if your timeout is short, you may get this error, like:
3. Your SQL statement was killed
Some systems will actively kill SQL statements that are running too long, we can check if this might happen by looking at the number of kill statements that have been executed.
Check that the mysql request connection process is actively killed:show global status like "com_kill";
4. Your SQL statement is too large
Slightly harder to test and verify, but MySQL uses the largest packet station site for communication between server and client. If the statement contains large fields, it may be aborted due to the size of the SQL statement.
We can check the maximum allowed packet size through the statement:show global variables like "max_allowed_packet"; (1024*1024*5=5242880)
If the value is relatively small, you can set a larger value:set global max_allowed_packet=1024*1024*16;
If the modification is not big enough, you can continue to increase it.
Note: The size set via the command line is only valid for this time and will return to the original value after a reboot. The parameters can be set permanently by modifying the configuration file (my.ini).