General error: 2006 MySQL server has gone away

This is the error I am suddenly getting.

Additional uncaught exception thrown while handling exception.

PDOException: SQLSTATE[70100]: Unknown error: 1317 Query execution was query

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone query

After doing some research it sounds like a custom module, which I have made, is attempting a query which is too big. A solution that seems to work for a lot of people is this:

  1. Open my.ini
  2. Change “max_allowed_packet” from “1m” to “16m” (or larger)
  3. Save my.ini and restart MySQL

However, I am on a shared server, so I cannot edit my.ini, and although my provider has confirmed to me that the value is set to 1M, they won’t increase it.

I also tried adding this: ini_set('mysqli.reconnect', 'on'); to settings.php. It didn’t solve the problem.

Does anyone know of a another solution, or work around?



Shared hosting companies do not give away the SUPER privilege. If you have it, you can easily set max_allowed_packet to 512M by just running this :

mysql> SET GLOBAL max_allowed_packet = 1024 * 1024 * 512;

No restart is required. Then, all incoming connections thereafter can have a 512M packet.

You cannot do this:

mysql> SET max_allowed_packet = 1024 * 1024 * 512;

because you get

ERROR 1621 (HY000): SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value

The only alternative I can think of is to switch to Amazon EC2 and install MySQL there. That way, you can have free rein to edit my.cnf/my.ini and have the SUPER privilege.

Leave a Reply

Your email address will not be published. Required fields are marked *