MySQL Error Messages: MySQL server has gone away & Lost connection to server during query
For vBulletin forums, the most common reason for the MySQL server has gone away error:
1. Is that the server timed out and closed the connection. By default, the server closes the connection after 8 hours or 28800 seconds if nothing has happened. This value is too high for vBulletin usage, so usually it’s lowered to anywhere between 30 to 60 seconds. But it all depends on the server and forum traffic, so it can vary all the way from 900 to 1800 seconds. You can change the time limit by setting the wait_timeout in /etc/my.cnf as well. Make sure to restart MySQL server after making changes to /etc/my.cnf file. So if your vBulletin forum continues to get the MySQL server has gone away or Lost connections to server during query error messages, keep raising the wait_timeout value in 60 second increments until the error message is gone. Now that is fine if you have a dedicated server or VPS server with root access. However, if you are on shared hosting server you won’t have root access to make changes in your /etc/my.cnf file, so will need your web host to make the changes. Now some shared web hosts will not make these changes as they are global changes, so it affects all shared hosting accounts on the server and not just yours. As I said each forum’s traffic and usage patterns will determine the optimal wait_timeout value and that can differ from one shared hosting account’s forums to another. So most likely you’d need to move and change web hosts to one that provides more accommodating MySQL /etc/my.cnf file options. Remember, default value for wait_timeout is 28800 seconds. Read the bottom of this post to find out how to check what your wait_timeout value is for the server you’re on.
2. Another common reason to receive the MySQL server has gone away error is because you have issued a “close” on your MySQL connection and then tried to run a query on the closed connection. Simply your host may have restarted MySQL in a middle of an query or they have cronjobs scheduled to restart MySQL server for whatever reason. Sometimes, the MySQL error messages are delayed and queued in the mail server for delivery, so check the time stamp of the actual MySQL error message and compare it to your server time. You can check that the MySQL hasn’t died by executing mysqladmin version and examining the MySQL uptime.
To check mysql uptime, in shell as root user type:
mysqladmin -u root -p version
If you don’t have SSH telnet access to your server, read the bottom of this post to find instructions on how to check the MySQL Status output page for the uptime value in seconds.
Database error in vBulletin 3.8.6: Invalid SQL: SELECT postid, post.title, pagetext, post.threadid, thread.title AS threadtitle FROM post AS post INNER JOIN thread AS thread USING(threadid) WHERE postid = 3160513; MySQL Error : MySQL server has gone away Error Number : 2006 Request Date : Tuesday, March 15th 2011 @ 05:14:38 AM Error Date : Tuesday, March 15th 2011 @ 05:14:39 AM Script : http://forumdomain.com/forums/editpost.php?do=updatepost&p=3160513 Referrer : http://forumdomain.com/forums/editpost.php?do=updatepost&p=3160513 IP Address : xxx.xxx.xxx.xxx Username : mysqlusername Classname : vB_Database MySQL Version :
3. You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big
BLOB columns), you can increase the query limit by setting the server’s
max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given on MySQL.com documentation site at Section C.5.2.10, “
Packet too large”. For vBulletin forums, raising max_allowed_packet value from 1M default to something higher in /etc/my.cnf may help. Between 16M to 64M usually enough but as high as 128M to 256M may help.
Note: You can find out what your web host set for MySQL variable options by default by going into your vB forum Admincp to check:
For vBulletin 3.x:
- Go to Import & Maintenance -> Diagnostic menu at very bottom of left frame and run MySQL Variables and MySQL Status output. There should be a wait_timeout value for MySQL Variables
For vBulletin 4.x
- Go to Maintenance -> Diagnostic -> System Information menu at very bottom of left frame and run MySQL Variables and MySQL Status output. There should be a wait_timeout value for MySQL Variables
It will be near end of the output.
version 5.1.56-log version_comment MySQL Community Server (GPL) version_compile_machine i686 version_compile_os pc-linux-gnu wait_timeout 30