search

Home  >  Q&A  >  body text

MySQL Error 2006: The mysql server has disappeared

<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>
P粉786432579P粉786432579458 days ago607

reply all(2)I'll reply

  • P粉478835592

    P粉4788355922023-08-24 16:55:06

    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 is 4194304, which is 4MB.)

    [mysqld]
    max_allowed_packet=16M

    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.

    reply
    0
  • P粉752290033

    P粉7522900332023-08-24 12:28:45

    It might be easier to check if the connection exists and re-establish it if needed.

    For information, see PHP:mysqli_ping.

    reply
    0
  • Cancelreply