Recently i optimize my WordPress for performance with many tweaks like deleting useless tables from database. Installed WP-Super cache, etc.
I was checking the error_log file in my Filemanager i was shocked due to its size, it was 14MB large !. I download it and opened it, all the errors were related to Database.
Almost all lines were starting with
“WordPress database error MySQL server has gone away for query…..”
and few were like this
“WordPress database error Lost connection to MySQL server during query for query…..”
As per the Error statement, the error clearly notifies that the connection between the WordPress and MySQL database was not proper. I just searched Google and seen many results, then i got the idea that its a General problem for many wordpress users.
Rob given a solution for this problem with few patched files to be replaced, You can read his article “Workaround for WordPress database error“. The article give detailed information about this problem. He also given files to be replaced to solve this problem.
According to him, This error is cause due to improper coordination between database and WordPress PHP commands.
According to Rob ,
When someone tries to view one of your WordPress web pages, the PHP code first opens a connection to the MySQL server. Subsequent queries to the MySQL server rely on the connection remaining open, and do not re-open the connection. If the connection to the server happened to have shut down before a query is made, then WordPress will display this error.
So for that you need to change the value of “wait_timeout” variable, either ask your site hosting admin to do it for your else you can do it by your self by tweaking your wordpress file named wp-db.php.
Rob given replacement files for WordPress upto version 2.6.1 but recently WordPress 2.7 is released so how to do the patch for WordPress 2.7 ?
Here i am including the file to be replaced by original “wp-db.php” file for WordPress 2.7.
Make sure you Backup your database and other files.
In above Workaround file, i just added
$this->query("set session wait_timeout=600");
in line number 334 in original file.
So do Check your Error log file today, else this may cause increase in your site loading time.



Dec 16, 2008 at 2:53 pm
I have encountered this. i WILL TRY THIS SOLUTION OUT.
Reply to this comment
Dec 22, 2008 at 6:16 pm
I have never encountered this before but thanks for the information. It is always good to “know”
Reply to this comment
Dec 24, 2008 at 1:07 am
well, hi admin adn people nice forum indeed. how’s life? hope it’s introduce branch
Reply to this comment
Jan 5, 2009 at 5:54 am
Thanks for the help!
Reply to this comment
Feb 8, 2009 at 12:00 pm
But why would a query take that much time??
I don’t think this happens except for the case that you are installing something new(it took longer only when I tried to install 60 plugins at the same time)
There must be something else taking time (may be some backup plugin or something like that).
Reply to this comment
Apr 8, 2009 at 8:42 am
Hi !!
My name is Piter Kokoniz. oOnly want to tell, that I’v found your blog very interesting
And want to ask you: what was the reasson for you to start this blog?
Sorry for my bad english:)
Thank you:)
Your Piter Kokoniz, from Latvia
Reply to this comment
Aug 11, 2009 at 10:55 am
I had changed the wp-db.php file but the same error occurs when i reply to any post,
If you have any solution regarding this please send.
Thanks in advance
Reply to this comment
Jul 9, 2010 at 8:55 pm
Or you could just set the variable in your my.cnf file on your database setup. This would make it so the solution would good even when you upgrade. Why make it harder then it is….
Reply to this comment