MySQL Error 2006: The mysql server has disappeared
P粉786432579
2023-08-23 17:47:00
<p>I run a server at my office to process some files and report the results to a remote MySQL server. </p>
<p>File processing takes some time and the process terminates midway with the following error: </p>
<pre class="brush:php;toolbar:false;">2006, MySQL server has gone away</pre>
<p>I've heard about the MySQL setting <strong>wait_timeout</strong>, but do I need to change that on my office server or a remote MySQL server? </p>
I've encountered this situation many times and usually find the answer is
max_allowed_packet
.Raising the value in
/etc/my.cnf
(under[mysqld]
) to 8 or 16M usually fixes the problem. (The default in MySql 5.7 is4194304
, which is 4MB.)Note: If the row does not exist, just create the row, it must appear as an entry under
[mysqld]
NOTE: This can be set while the server is running, but it will be lost after the mysql daemon is restarted. Use
SET GLOBAL max_allowed_packet=104857600
(this sets it to 100MB)Note: On Windows, you may need to save your my.ini or my.cnf file using ANSI instead of UTF-8 encoding.
It might be easier to check if the connection exists and re-establish it if needed.
For information, see PHP:mysqli_ping.