Workaround for WordPress database error: [MySQL server has gone away] for different versions of WordPress

July 16th, 2007

November 26, 2010 – If you would like a patched file for other versions of WordPress besides the ones listed here, you can email me at wpmysql at(@) robsnotebook.com and I will tell you my fee.

For those of you who have received the WordPress error message “WordPress database error: [MySQL server has gone away]“, I made a change to a WordPress PHP file that makes it so you will probably never get this error again.

There are several possible causes to getting this error. Further down in this article, I will describe what I think is happening and some things that you can do (other than this workaround) to diagnose and fix the problem.

Installing the Workaround

There are 2 workarounds, you can use either one of them, although one of them has better performance than the other.

  1. wp-db-x.y.z-workaround.phptxt
    • The latest version of the workaround with the best performance. This latest workaround is available for all versions of WordPress that are listed in this article.
  2. wp-db-x.y.z-workaround-old.phptxt
    • The original version of the workaround with less than optimal performance. Since I am no longer maintaining that version, I only have it posted for the versions of WordPress that I had originally posted it for. This workaround is based on the work of openadvent.

To install the workaround, download the “workaround” or “workaround-old” version of the wp-db…phptxt file, rename it to wp-db.php, and copy it to wp-includes/wp-db.php (overwriting the old file). You may want to backup the old file instead of overwriting it. You’ll need to do this each time you upgrade WordPress (a pain, I know), with the appropriate version of wp-db.php for that version of WordPress.

WordPress Versions not listed here

I can create them for you for a fee. Send email to wpmysql at(@) robsnotebook.com and I will tell you the fee.

WordPress 2.8.1

There was no change in wp-db.php from 2.8 to 2.8.1, so use the 2.8 file.

WordPress 2.8

Workaround wp-db.php
Original wp-db.php

WordPress 2.7.1

There was no change in wp-db.php from 2.7 to 2.7.1, so use the 2.7 file.

WordPress 2.7

Workaround wp-db.php
Original wp-db.php

WordPress 2.6.1

There was no change in wp-db.php from 2.6 to 2.6.1, so use the 2.6 file.

WordPress 2.6

Workaround wp-db.php
Original wp-db.php

WordPress 2.5

Workaround wp-db.php
Original wp-db.php

WordPress 2.3.3

There was no change in wp-db.php from 2.3.2 to 2.3.3, so use the 2.3.2 file.

WordPress 2.3.2

Workaround wp-db.php
Workaround-old wp-db.php
Original wp-db.php

WordPress 2.3.1

There was no change in wp-db.php from 2.3 to 2.3.1, so use the 2.3 file.

WordPress 2.3

Workaround wp-db.php
Workaround-old wp-db.php
Original wp-db.php

WordPress 2.2.3

There was no change in wp-db.php from 2.2.1 to 2.2.3, so use the 2.2.1 file.

WordPress 2.2.2

There was no change in wp-db.php from 2.2.1 to 2.2.2, so use the 2.2.1 file.

WordPress 2.2.1

Workaround wp-db.php
Workaround-old wp-db.php
Original wp-db.php

WordPress 2.1.2

Workaround wp-db.php
Workaround-old wp-db.php
Original wp-db.php

Why This Happens

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.

One reason that the connection may shut down is if it has been idle for “wait_timeout” seconds since the last access to the connection. “wait_timeout” is a system variable in your MySQL server configuration. I have created a tool to allow you to check the value of “wait_timeout”.

Tool for checking “wait_timeout”

Changing the “wait_timeout”

If your “wait_timeout” variable is small, and your CPU is heavily loaded, it may make it more likely that your connection to the MySQL server is shut down prematurely.

If your “wait_timeout” is too small, and you have admin access to your MySQL server, it is possible to change the default value of “wait_timeout” by editing a file such as /etc/my.cnf, and restarting your MySQL server.

If you don’t have admin access (you are on a shared host), there is a way to change the “wait_timeout” variable for the MySQL session, but you need to modify the wp-db.php file (either the workaround version or the original version).

To change the “wait_timeout” to 600 in the wp-db-x.y.z-workaround.phptxt, uncomment (remove the “//”) the line:

// $this->query("set session wait_timeout=600");

You can also change the wait_timeout in the original wp-db.php file (if you choose not to use the workaround) by adding the above query line for changing the wait_timeout variable into the wp-db.php source. The place to insert the line is inside the “__construct(…)” function after the closing brace ‘}’ of the “if (!$this->dbh) {” statement.

What the Workaround Does

The original workaround posted in this article (labeled “workaround-old” now) was originally conceived by openadvent. In that workaround, PHP code was added that would try to “ping” the mysql server before each query. If this ping was unsuccessful, then the workaround would try to reopen a connection to the MySQL server and then repeat the query. The connection would try to be reopened and queried 4 times before declaring a failure.

The newer workaround that I have on here now does not do this ping, giving better performance. Instead, it just tries to perform the query. If the query is successful, the PHP code continues on, and no new connection to the MySQL server is opened. If the query fails, the PHP code will try to reopen the connection and do another query. Just like the old workaround, the connection would try to be reopened and queried 4 times before declaring a failure.

Another Possible Fix

One person posted in the comments that by switching from PHP 4 to PHP 5, he was able to get rid of this error. Perhaps his PHP 4 implementation was running just slow enough that it was exceeding the timeout, and PHP 5 was running fast enough to avoid the timeout. When I originally encountered this error, I was using PHP 5, so switching from PHP 4 to PHP 5 may not solve the problem.

See Also:

Open Advent Blog with fix for WP 2.1.2

WordPress Support Site

Vbulletin Forum

208 Comments

  1. Cmbon 05 Aug 2007 at 4:26 am

    Hey, Rob,
    Thank you! It has fixed the error in my blog.

    Weki.cn

  2. Kevin Makiceon 07 Aug 2007 at 4:30 pm

    I think it worked for me, too. The admin site is still painfully slow, but I can get back into it for the first time in six hours.

  3. Robon 11 Aug 2007 at 12:28 pm

    I checked out WordPress version 2.2.2, and there is no change in wp-db.php from 2.2.1 to 2.2.2, so I added a note to use the 2.2.1 file for 2.2.2.

  4. Neriakon 22 Aug 2007 at 7:45 am

    Heya Rob, thanks a ton for that fix. You really saved me from going through a lot of trouble! :)

  5. kenon 04 Oct 2007 at 7:13 am

    hey, how about WordPress 2.3?
    TQ

  6. Robon 05 Oct 2007 at 12:19 am

    Fix for WordPress 2.3 was just added.

  7. kenon 05 Oct 2007 at 10:49 am

    Thanks Rob! great fix for WP 2.3
    & it seems fix for WP 2.2.1 also works fine for WP 2.3
    Great job!

  8. Robon 05 Oct 2007 at 11:06 am

    I wouldn’t recommend using the WP 2.2.1 fix for WP 2.3, since when I did the update, I noticed that they added some things into wp-db.php for WP 2.3.

  9. bakkouzon 08 Oct 2007 at 8:35 pm

    heya Rob,
    Thank you for the fix, i just applied it and it works just fine.
    the strange thing in my case though that the error wasn’t sitewide, but was appearing on a single post only, my most recent post, and only with my comments and not other people’s, any idea why? :)

  10. Jay Ton 17 Oct 2007 at 3:10 pm

    Rob – THANKS! for this. Worked like a charm on my 2.3 blog. You da man!

  11. [...] file in version 2.1. Because I recently upgraded to WP 2.3, I applied the file fix again. It is at this site if anyone else needs [...]

  12. Willon 25 Oct 2007 at 6:23 pm

    Thanks! I had applied the fix for version 2.1 and forgotten about it since it worked so well. Now that I am on Version 2.3 I have been getting some timeouts and the “Lost Connection to the MySQL Database” error, followed, of course, with the “gone away” error.
    Hopefully I have fixed it by downloading your file to replace the one that came with 2.3.

    Really appreciate your effort on this and have posted and linked to your fix.

    -Will

  13. kentoon 28 Oct 2007 at 11:40 am

    Thanks mate! I’m using WP 2.3.1

  14. [...] Investigando un poco he encontrado la solución. [...]

  15. Robon 30 Oct 2007 at 9:12 am

    Please don’t link to the fixed php files directly on your blog, since I do release new versions when there are new releases of WordPress (and I would also like to get the ad traffic). If you do want to link, use the one to this page: http://robsnotebook.com/wordpress-mysql-gone-away. Thank you.

  16. [...] Download the fix here [...]

  17. Jan Dembowskion 31 Oct 2007 at 7:16 am

    Much thanks! I diffed the 2.3 v 2.3.1 wp-db.php file and except for a trailing line feed there was no difference. Your fix worked so far :)

  18. Kanokon 08 Nov 2007 at 8:14 am

    The Flick photo page on my blog gone error when I upgrade the plugin to v0.93.1 which use database to keep the image cache in the DB. Your mod fixes the problem..

    Thanks a lot
    Kanok

  19. [...] Yes, this error happened to me too. It seems there are plenty of hosters who just don’t bother configuring and tuning mySQL and this is definitely not quite a WordPress issue (at least I can’t believe it runs heavy queries when adding a new post), but there is a workaround Problem explanation and download link [...]

  20. [...] pingback [...]

  21. More Blog Moneyon 02 Dec 2007 at 3:54 am

    I used the 2.1.2 file for WP2.1.3 and it’s working so far.

    Thanks!
    mbm

  22. [...] Origional complete article link with more details [...]

  23. WordPress Mysql Has Goneon 11 Dec 2007 at 1:41 pm

    [...] information get from : fix for wordpress database error [...]

  24. shadowX_19on 11 Dec 2007 at 11:42 pm

    thanks 4 the fix.. now my blog can run smoothly back..

  25. [...] created to the public for this issue. You may try visiting the following link for the resolution. http://robsnotebook.com/wordpress-mysql-gone-away Kindly let us know if the above link has solved your issue after you have replaced your [...]

  26. Patrick Wongon 18 Dec 2007 at 11:04 pm

    Thanks. I have been pulling my hair when this error shows up. I even phoned my hosting company but they say it’s not their end. Anyway, I took your suggestion and see if this fixes the problem!

  27. [...] Fix for WordPress database error: [MySQL server has gone away] for different versions of WordPress – MySQL server has gone away wordpress error [...]

  28. ECon 28 Dec 2007 at 7:21 am

    I got exactly the same problem, but I have been running a very old version of WordPress – 2.1. I copied the 2.1.2 fix and replaced my wp-db.php with it, but i get an error message “Fatal error: Call to undefined function: hide_errors() in /home/lasermk/public_html/wp-includes/functions.php on line 913″

    Any idea how to get round this? Many thanks in advance.

  29. Robon 03 Jan 2008 at 7:32 pm

    It seems that wp-db.php did change from WP version 2.3.1 to 2.3.2. I have posted the fixed 2.3.2 file in the article.

  30. [...] ???????????????? Fix for WordPress database error: [MySQL server has gone away] for different versions of WordPress [...]

  31. [...] created to the public for this issue. You may try visiting the following link for the resolution. http://robsnotebook.com/wordpress-mysql-gone-away Kindly let us know if the above link has solved your issue after you have replaced your [...]

  32. [...] I upgraded to WordPress 2.3.2, I have noticed a really strange error.  I am trying a fix found here, and this post is partly a test to see if it [...]

  33. bayuon 01 Feb 2008 at 1:14 am

    Thanks mate… you’re my savior

  34. Erickon 19 Feb 2008 at 10:37 pm

    Hi. Please CC me if you respond to this (you don’t have comment subscription).

    I did this. And it works — thanks for this hack!

    But I would additionally like to use “mysqli_” instead of “mysql_” functions for better MySQL 5 performance. Any way we can change that in just one file and be done with it, or are queries scattered all over?

  35. Martin Cleaveron 24 Feb 2008 at 8:10 pm

    http://trac.mu.wordpress.org/ticket/376 says:

    07/24/07 16:07:35 changed by donncha

    “Check your MySQL wait_timeout variable. What is it set to. It’s likely that it’s way too low. Try setting it to 600 or higher. The solution offered by the link above suggests not reusing an existing connection but that doesn’t make sense and would severely reduce performance on your server.”

  36. Robon 24 Feb 2008 at 9:23 pm

    Thanks Martin for that tip. Based on your suggestion, I just tried to find a way to find out what my MySQL wait_timeout variable is, but I haven’t figured it out yet. I’m sure if I kept looking, I’ll find it, but if you know it and can say how to do that, it would be great.

  37. Martin Cleaveron 24 Feb 2008 at 10:04 pm

    I altered the variable to value 600 in /etc/my.cnf – but you may be unable to change this on machines where you don’t have root access.

    http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#option_mysqld_wait_timeout has the description for this variable. You may find this useful in discovering how to set the value interactively.

  38. Robon 24 Feb 2008 at 11:40 pm

    Thanks Martin. I don’t have root access, but I think I found a way to discover the value of my wait_timeout variable. I sshed into the server and executed “mysqladmin -u username -p variables”. It shows that the wait_timeout variable is 60. Do you think that this is too small?

  39. Robon 24 Feb 2008 at 11:43 pm

    I’ve also been meaning to change this “fix” (Hack really is the appropriate word). I originally just used openadvent’s idea to ping the connection to see if it is still open (and only reopening the connection if the ping is unsuccessful). I think a better way would be to just perform the query, and only open a new connection if the query fails. This way, the only penalty in performance is when the query fails. If the query is successful, there is no penalty. Someday soon I will make this change and do another post with it.

  40. [...] was just looking at RobsNotebook.com and came across a really good solution to a common problem with [...]

  41. skarldon 13 Mar 2008 at 8:26 am

    In a recent upgrade, 1and1 hosting has broken my site. This looks like the fix. However, I am at version 2.0.11. Has this been tested at that level, or will I need to upgrade to a later release of WP? Are there plans for 2.5?

  42. Robon 13 Mar 2008 at 1:33 pm

    skarld: The earliest version that I have done this for is 2.1.2 (I never tested any earlier version). One option for you if you do not want to upgrade is to make the changes yourself in your version of the wp-db.php file. You can look at what I have here as the original for 2.1.2 and the fix, and you can insert the changes yourself. I’m a little busy these days, otherwise I would look into making the change for you myself.

  43. skarldon 13 Mar 2008 at 11:39 pm

    Thanks for the suggestion. It did not work.
    My host suggested PHP5. Stating the following:

    Try switching to PHP5. Scripts parsed in PHP4
    use more memory than PHP5 in our systems. You can switch to PHP5 by
    adding line below in your .htaccess file:

    AddType x-mapp-php5 .php

    It worked.

  44. Robon 14 Mar 2008 at 12:02 pm

    When I first got this error, I was using PHP5. I think it is a very sporadic error and only really occurs when your server is highly loaded (especially shared hosts). I would say that the error maybe only occurs 1% of the time, but when the condition that causes the error occurs, the workaround in this script will try to reconnect with the MySQL server.

  45. » It’s Resolved!! » naziebiyahon 15 Mar 2008 at 11:30 am

    [...] server has gone away]. Dan, oh thanks God for creating the creator of google, saya pun menemukan ini. And it shows the problem and the solution too.. Dan akhirnya bisa!! [...]

  46. [...] goodness the solution is not very hard. My hastyhost found this solution and helped me with the upload the first time round. Today, I had to do it myself, using WIFI in a [...]

  47. Robon 26 Mar 2008 at 10:00 pm

    I rewrote the article and added a new workaround that does not do the ping – increasing the performance. The article also gives more information for diagnosing the problem, such as looking up the value of the “wait_timeout” MySQL variable, and how to change this variable.

  48. Robon 01 Apr 2008 at 8:25 am

    I added the workaround for WordPress 2.5.

  49. [...] must be something in WordPress itself that causes this error and I found a workaround for it here: Workaround for WordPress database error: [MySQL server has gone away] for different versions of Word… I did what it said to do and now my blog is back! *whew* __________________ Army Mom: New [...]

  50. [...] if you ever get an error like that then you need to get the workaround from Rob’s Notebook. It saved my sanity… it will save yours. It was very, very easy to [...]

  51. Charlotteon 04 Apr 2008 at 8:21 pm

    Rob.. thank you so much for this. I was about to pull my hair out. This saved my hair, sanity and my blog!

  52. WordPress????????? | ????on 10 Apr 2008 at 10:26 pm

    [...] UPDATE 2008.04.11????????????????wp-db.php????????????????????????????????????????????????? [...]

  53. Surpasshosting ????(2) - Shawn's Blogon 20 Apr 2008 at 4:13 am

    [...] WP-DB ???????? MySQL ??? Ping MySQL ?????????? error-log [...]

  54. ?ukasz Sobekon 26 Apr 2008 at 3:50 pm

    The db file of 2.5.1 is identical to that of 2.5

  55. LaurenMarie - Creative Curioon 02 May 2008 at 9:39 am

    Hi Rob, it looks like this could help me, but uploading the file you provided for 2.5 isn’t working for me. I would like to try the modification you listed for the wait_timeout variable, but I can’t find that line in order to uncomment it. Which line number should it be on?

    If you have time, maybe you can check out my problem and solutions I’ve tried.

  56. Widgett Wallson 16 May 2008 at 2:14 pm

    Echoing LaurenMarie’s comment–couldn’t find the line either for the 2.5 flavored file.

  57. Robon 16 May 2008 at 2:15 pm

    Yes, it is missing from the 2.5 file. I will add it. In the meantime, you can look at one of the other versions as it is there in the other versions, and put it in the same place in the 2.5 version.

  58. QuicksWebon 18 May 2008 at 6:29 pm

    I wonder why if this works and default wordpress does not, why did they not adopt this into their original releases.

    It’s been going on a long time now.

  59. Robon 18 May 2008 at 9:58 pm

    I just updated the 2.5 version so that the commented line that allows you to change the wait_timeout is now there.

  60. Simonon 20 Jun 2008 at 3:54 am

    Thanks so much, I was getting another error,
    “Fatal error:Call to undefined method:wpdb->set_prefix()”

    and this sorted it, much appreciated, Simon

  61. rahulon 26 Jun 2008 at 9:37 pm

    my site database give problem any one know how to fix this plz help me site is http://www.znvj.com

  62. Kerryon 29 Jun 2008 at 1:48 pm

    Dude, you are a lifesaver! Thanks so much!

  63. Joseon 18 Jul 2008 at 8:21 am

    I’ve tested the 2.6 fix and it says it can’t connect to the database :?

  64. Joseon 18 Jul 2008 at 8:54 am

    Sorry, the problem is that it can’t SELECT the database :oops:

  65. Robon 18 Jul 2008 at 10:10 am

    OK, I’ll see if I have some time to test 2.6 this weekend and see what the problem is.

  66. Dana Huffon 18 Jul 2008 at 5:14 pm

    Just FYI, I tested and had the same problem as Jose.

  67. Robon 18 Jul 2008 at 10:05 pm

    I found the problem with my untested version for 2.6 and I fixed it, tested it, and the 2.6 version on this site is now updated with the fix. Please let me know if you have a problem.

  68. Rob Cubbonon 01 Aug 2008 at 2:29 pm

    Hey Rob, I just got a message from a reader of my blog to say that I got a MySQL server has gone away error when he’d tried to comment on a post. I tried to reply and I got the same thing. Strange as everything had seemed to be working before this since I’d upgraded to 2.6. Anyway, I’ve employed your fix and everything seems to be OK now. Thanks a million, Rob. Rob!

  69. [...] this WordPress defect, then I found that there are several possible causes to getting this error. Rob explains the error in his blog post. When someone tries to view one of your WordPress web pages, [...]

  70. Ajayon 14 Aug 2008 at 3:19 am

    thanks rob

  71. ?????? DB ??? ? ???? ?? « Mc???on 18 Aug 2008 at 10:43 am

    [...] Workaround for WordPress database error: [MySQL server has gone away] for different versions of Word… [...]

  72. Navjot Singhon 27 Aug 2008 at 6:27 am

    Thanks a lot. It worked for me wonderfully.

  73. Sid Khullaron 28 Aug 2008 at 1:08 am

    Hi Rob,

    Anywhere I look for this error, I’m referred to your site. :)
    The problem is I’ve tried your fix and:

    1. With the normal wp-dbi I get an upgrade->server gone away loop
    2. With your fix installed, I get a blank page

    My front end isn’t working too.
    Please, PLEASE help if you can.

    Thanks,

    Sid

  74. Sid Khullaron 28 Aug 2008 at 1:10 am

    Hello Rob,

    An interesting this just happened. All that was happening in my previous message – just stopped happening, and my site is working again.

    Thank you Sir!

    Sid

  75. Steveon 28 Aug 2008 at 3:14 pm

    It would be nice to have a this app for the new version 2.6.1!

    Thanks!

  76. Robon 30 Aug 2008 at 12:38 pm

    For 2.6.1, there was no change in the wp-db.php file, so use the 2.6 version.

  77. [...] Original complete article link with downloadable fixes for all WordPress versions [...]

  78. [...] (Esta versión es para WordPress 2.6 y WordPress 2.6.x, si queréis para versiones antiguas tenéis más aquí). La subiremos a wp-includes/wp-db.php (haciendo preferiblemente una copia de la existente), y [...]

  79. Niharon 22 Sep 2008 at 1:52 am

    Great!!!!

    Thanks a ton. applied the changes to wp-db.php file. thanks again…

  80. Lutfion 24 Sep 2008 at 5:22 pm

    It works for me.
    Thanks alot.

  81. swim.roon 28 Sep 2008 at 7:01 am

    Thanks. It worked for me.

  82. Mikeon 06 Oct 2008 at 6:33 pm

    You are a true hero. I have no idea why this worked but you fixed a big problem for me!

  83. MaJaon 21 Oct 2008 at 5:17 am

    thx for the fix.
    i freaked out when i saw the error.
    made a quick google search.
    found ur fix for the problem.
    n everything turns out fine.
    thx again

  84. Johnon 23 Oct 2008 at 11:55 pm

    Thanks Rob,

    Your workaround fixed my problem. You are The Greatest!!

  85. tobiason 11 Nov 2008 at 4:22 pm

    the reason for “mysql server has gone away” in my case has been a too large sql query. while the content field for options in wordpress is defined as longtext (~2^32 bytes), the connection between php and the mysql server has a much smaller restriction: max_allowed_packet. in my case this was set to 1 mb (afaik, the default value). the option table entry is clearly above (~2mb). i figured this out after some debugging using your queryWithReconnect function. after setting max_allowed_packet to 16M in the [mysqld] section in my.ini, everything worked flawless.

    bye,
    tobias

  86. A technical glitch | F-Shaperson 12 Nov 2008 at 11:14 am

    [...] access the MySQL database but I’ll spare you the technical details (those interested can click here for the full details). Suffice to say that I felt a massive load of my mind when it finally worked [...]

  87. [...] Workaround for this MySQL problem has been best addressed in this article. [...]

  88. emilianoon 16 Nov 2008 at 1:54 pm

    hey!, hello. i have WP 2.7 (Beta2) and i need this solution, but is not available. ¿will work the Workaround for WP 2.6 in WP 2.7? Thanks.-

  89. [...] this doesn’t solve your problem, try the workaround by [...]

  90. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  91. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  92. [...] por lo general en su admin páginas. Workaround for this MySQL problem has been best addressed in this article . Para evitar este problema de MySQL ha sido la mejor forma de abordar en este [...]

  93. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  94. Michaelon 29 Nov 2008 at 9:59 am

    Many thanks to you, Rob, for this excellent workaround.

  95. FaRoFraKon 11 Dec 2008 at 7:23 am

    Hi,

    wordpress 2.7 is new, but this too has the bug? or already arranged?

  96. [...] error MySQL server has gone away” -tyyppistä virhettä. Googlasin vähän ja löysin workaroundin, jota aionkin kokeilla heti kun saan muut ongelmat korjattua. Näiden jälkeen olisi vielä [...]

  97. Chrison 12 Dec 2008 at 8:47 pm

    I am out of the blue getting this MySQL error, but I tried installing this fix and it didn’t work. I’m running WP 2.7. Is the most recent fix compatible with 2.7?

  98. Robon 13 Dec 2008 at 10:52 am

    The fix for WordPress 2.7 has been added to this page.

  99. phottehemon 19 Dec 2008 at 7:21 am

    Hi people

    As a fresh robsnotebook.com user i only want to say hi to everyone else who uses this bbs B-)

  100. Linaon 23 Dec 2008 at 5:48 am

    Thank you so much! it’s a great solvation of kind of panic.

  101. kenton 02 Jan 2009 at 9:28 pm

    It’s not clear in your “That Darn Caffeinated Content Update!” email if the title fix is in the fix on this page. I haven’t seen the “WordPress database error: [MySQL server has gone away]” error, so I’m hesitant to apply it.

    Please advise, Kent

  102. [...] It seems the problem is caused by heavy load from your hosting server. The workaround can be found here. If your “wait_timeout” variable is small, and your CPU is heavily loaded, it may make it more [...]

  103. GMZon 14 Jan 2009 at 5:23 am

    Thank you so much. Your solution helped me resolve my problem, after WordPress was not showing any post, widgets, nada. Tech support of my hosting adviced me to reinstall wordpress (that meaned backup of important files, backup of database, I have a headache just thinking). The only problem now is that my blog still loads kinda slow. Would you recommend a plugin for cache?

  104. Robon 14 Jan 2009 at 9:16 am

    GMZ and all:

    This “workaround” that I have published is really just a band aid for the majority of problems. WordPress should not take so long to create a page, and if your wait_timeout is set high enough, you shouldn’t get this error message. Many people get this error because they have many plugins that do many mysql queries, slowing wordpress down. The real way to fix this problem is to find what is slowing your WordPress down so much – which can be a tedious process. One way to do this would be to disable 1 plugin at a time to see if it makes the problem go away.

    I’ve been meaning to update the article for a while to say this.

  105. [...] blah error. For all kinds of things. And when looking for the solution, I was reminded of this: Rob at Rob’s Notebook reworked the wp-db.php file to avoid such things. And surprisingly, searching for “WordPress database error MySQL server has gone away” took me a [...]

  106. azzon 11 Feb 2009 at 1:51 am

    thank man, your solution really help me alot, thank again

  107. Apache Error Logs | Web Analyticson 16 Feb 2009 at 12:54 am

    [...] One of my blog’s plugins was the source of many of the issues.  That was an easy enough solution — I just deactivated and uninstalled it.  The MySQL connection was lost.  It’s a relatively simple fix for WordPress users, detailed right here. [...]

  108. WWWon 17 Feb 2009 at 3:45 pm

    The Workaround wp-db.php worked great for WP 2.7, but when I upgraded to WP 2.7.1 just days ago, it no longer worked. Now that I’ve rolled back to the original wp-db.php that came with 2.7.1 I’m getting the nasty old “MYSQL server has gone away” message again. Is anyone else having problems with the fix not working with 2.7.1 and is there a fix for the fix so that it WILL work in 2.7.1?

    Thanks!

  109. WordPress ???? | ???????on 18 Feb 2009 at 11:42 am

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  110. Fatoson 18 Feb 2009 at 3:29 pm

    I just wanted to say thank you for saving me time and my blog. The blog is new and I almost deleted/uninstalled the wordpress altogether and start all over again. But having written several post so far made me think again and I searched google for solution and luckily found your site.

    Keep up the good work
    Fatos

  111. WordPress ????????? - ???on 24 Feb 2009 at 2:42 pm

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  112. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  113. One with "Future problems like WWW"on 25 Feb 2009 at 4:26 pm

    @WWW

    I am about to have same problem, if I will use this script..

    WWW: Can you download the 2.7.1 version to your computer (unzip it), and just replace the wp-db.php (from zip-file) file from there to your site?

    Is there coming an update to this 2.7.1 version? I am too afraid to use this if my site ends up like Mr. http://WWW...

    PS. GREAT, that someone has done these modifications actively! Thanks for that! :)

  114. Sergio Ordoñezon 25 Feb 2009 at 8:04 pm

    Hello Rob, could you help me?

    Im having this error and my version is 2.1.3, do you know where to get the file?

  115. Robon 25 Feb 2009 at 9:35 pm

    I looked at 2.7.1, and it appears that there was no change in the official wp-db.php file. Therefore, the 2.7 workaround file should work in 2.7.1 also. I tested it and it works for me. I don’t know why WWW has a problem with it, but it worked for me.

  116. Robon 25 Feb 2009 at 9:38 pm

    @Sergio: I don’t have a workaround for version 2.1.3, but if you donate $30 to my site, I can create it for you.

  117. Andréon 01 Mar 2009 at 7:14 am

    Thank you sooo much! It worked for v2.7.1. :D
    You got a place at my favs. :P

  118. [...] Origional complete article link with downloadable fixes for all WordPress versions [...]

  119. WordPress ???? | Wpfanson 06 Mar 2009 at 5:40 am

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  120. Charleson 11 Mar 2009 at 4:32 pm

    I’ve been running into this with WPMU ver 2.6.5. What would it take to impliment this fix for WPMU?

    Thanks!

  121. maxisozlukon 14 Mar 2009 at 7:50 pm

    thx i will try this too after wp super cache .

  122. [...] Workaround for this MySQL problem has been best addressed in this article. [...]

  123. Felixon 20 Mar 2009 at 9:16 am

    This solution worked well for me. The SQL problem occured after switching to a php5 Server.

    Solution: But the folloving line in the beginning of your .htaccess file

    AddHandler php5-cgi .php

  124. [...] If it contains “WordPress database error MySQL server has gone away for query” then click here and dont [...]

  125. WordPress ????????? - Jeff-Chen.Comon 07 Apr 2009 at 11:29 am

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  126. [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  127. Vaibhavon 26 Apr 2009 at 12:48 am

    Thanks, really useful. Saved me from the mess. I was thinking my database has gone corrupt.
    Giving you a trackback from my blog!

  128. EVoon 07 May 2009 at 5:29 am

    Thanks alot. your solution worked for me :)

  129. WordPress ???? | ????on 24 May 2009 at 2:56 am

    [...] This WordPress daTabase error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages.?? WordPress ?????????????????????????????????????????????????MySQL ?????????????????????? [...]

  130. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  131. Jacqueson 11 Jun 2009 at 4:34 am

    Many thanks for this – am amazed that I can’t find significant discussion of the problem on the official WP support forums, but glad Google found you! I’m still having this problem in WP 2.8, by the way.

  132. [...] it eventually got to me, and I found this site after a 2 second [...]

  133. Alexaon 24 Jun 2009 at 10:50 am

    Any idea if there needs to be a change in your updated file for the 2.8 upgrade? I’m getting this error message while attempting an upgrade from 2.7.1 to 2.8.

  134. Germanon 03 Jul 2009 at 4:11 am

    Is there any version that can be used in WP 2.8 ? THXS.

  135. [...] [via] [...]

  136. Kevinon 13 Jul 2009 at 4:32 pm

    2.8.1 workaround?

  137. ??? » WordPress ????on 14 Jul 2009 at 2:35 am

    [...] MySQL ?????????????????????? [...]

  138. mohammad hassanon 15 Jul 2009 at 5:15 am

    hello all
    in need workaround for 2.8.1
    that older workaround for example 2.7 work by new version 2.8.1

    best regrds

  139. Robon 17 Jul 2009 at 11:43 pm

    Added the workarounds for versions 2.8 and 2.8.1.

  140. hendraon 19 Jul 2009 at 7:39 am

    Hey, thank rob…
    you save a lot of me time, thank in advance :P

    greeting, hendra
    Indonesia (there is no boom in here !!!, totally save)

  141. [...] gibt es wie Sand am Meer, Google liefert Rund 18.900 Treffer. Es gibt Workarounds für die Datenbank-Klasse – aber diese »Blenden« das Problem letztendlich nur aus. Mag natürlich schön sein wenn nur [...]

  142. Webmaster Blogon 29 Jul 2009 at 11:21 am

    I just recently started getting these errors when refreshing my sitemaps in Google XML sitemaps plugin. I’m not sure what I did to fix it, but I just let it run through it’s course and it eventually made the errors go away and still rebuilt my sitemap.

  143. WordPress Study Blog » WordPress ????on 05 Aug 2009 at 11:35 pm

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  144. sverreon 09 Aug 2009 at 11:22 pm

    Thanks! it worked, but one thing that I struggled with was that, when I copied and pasted the text, I left some empty spaces at the end of the file, and this created some problems, thanks to http://www.hongkiat.com/blog/wordpress-error-warning-cannot-modify-header-information/comment-page-1/#comment-426679 I managed to fix it.

    so.. if you get an ‘cannot modify header’ error after this fix, try to remove empty space in front of or at the end of this file.

  145. [...] huge thank you to Rob at Rob’s Notebook for creating the fix to this issue, and getting my blog back up and running [...]

  146. laoon 24 Aug 2009 at 2:46 pm

    Hi all, I got wordpress 2.8.4 and this same “WordPress database error: [MySQL server has gone away]” problem. Are you using the last fix (2.8) for this 2.8.4 version? Thx, lao

  147. [...] http://robsnotebook.com/wordpress-mysql-gone-away Categories: Malo mešano Tags: Comments (0) Trackbacks (0) Leave a comment Trackback [...]

  148. [...] discuss that subject with us, Melissa Bradshaw implemented — at least for this blog — a workaround to change the MySQL wait_delay settings ourselves.  Clever idea, and seemed to work for half a day — but now the problems have [...]

  149. vishnupriyaon 15 Sep 2009 at 5:53 am

    Hi, I am getting this error ( my sql server gone away) all time.
    I am using C api’s in my project.The connection is lost after 8 hours.( I have set hte wait_timeout to max which is 8 hours). How can i reconnect to the server? Thanks in advance

  150. Ianon 15 Sep 2009 at 6:25 am

    Is there a workaround for 2.8.4?

  151. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  152. [...] La Solución para este problema de MySQL se intenta abordar muy bien en este artículo. [...]

  153. Where is MySQL Gone Away? | am i works?on 11 Nov 2009 at 12:16 pm

    [...] Rob of Rob’s notebook had the almost perfect solution for it. He created a replacement file for ‘wpdb.php’ which takes care of this problem, yeah it is temporary and you have to remember to replace this [...]

  154. [...] La Solución para este problema de MySQL se intenta abordar muy bien en este artículo. [...]

  155. ,[...] robsnotebook.com is one must read source of tips on this subject,[...]

  156. Somoneon 05 Jan 2010 at 12:29 am

    Thank you so much. The 2.8 fix works wonders for wordpress 2.9 as well. No more MySQL server has gone away errors for this little black duck. Yippee.

  157. Pulsuz Sayton 10 Jan 2010 at 4:07 am

    Hi,
    Please, can you help me about this? I use wordpress MU and on my frontpage there is a forum which makes trouble. On every visit to this forum i got the error on error logs. This error like this:
    WordPress database error for query: query_name
    FROM xxxx_sfmembers
    JOIN vzd_users ON xxx_users.ID = xxx_sfmembers.user_id
    WHERE user_login = ‘admin’; made by sf_get_login_display_name

    I think the problem on my user`s database. I need solve this problem as this is productive site.

    Thank you.

  158. WordPress ???? « 1900on 15 Jan 2010 at 2:13 am

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  159. Slow WordPress Blog Speedup Tipson 18 Jan 2010 at 11:28 am

    [...] timing out prematurely. You’ll see this on shared hosting services a lot of times. I found a great post on robsnotebooks.com that shows how to do this and even provides a way for WP to automatically reconnect to the database [...]

  160. ravion 19 Jan 2010 at 10:54 pm

    hey i’m using wordpress 2.9. i am getting the my sql server has gone away error. please tell me wt all changes need to be done in wp-db.php file. reply please

  161. Mixaon 20 Jan 2010 at 9:28 am

    And for 2.8.6 ?

  162. Slow WordPress Blog Speedup Tips hyderabad…

     Subscribe to this blog by mail or by RSS and get free stuff!Slow WordPress Blog Speedup TipsThe Unofficial AdSense Blog was a prime example of a slow WordPress blog, and it got to the point where I needed to fix things. So here are some things you ca…

  163. [...] In case you’re having a WordPress blank page problem caused by ‘MySQL server has gone away’ – there is a solution that should work: http://robsnotebook.com/wordpress-mysql-gone-away [...]

  164. [...] results for this particular error message; this article seemed to be cited frequently in them: Workaround for WordPress database error: [MySQL server has gone away] for different versions of Word… __________________ ** Forum Re-Organization/Retired Forum Categories **User’s Guide : Answers [...]

  165. [...] they are monitoring something. :( I googled around and there is some really old stuff on topic: http://robsnotebook.com/wordpress-mysql-gone-away http://wordpress.org/support/topic/110182 Had anyone encountered this? Is that core hack only [...]

  166. Sara Bruceon 21 Mar 2010 at 1:21 am

    Hello,
    Decent to be here.Good job buddy.

  167. [...] Connection to MySQL server is shut down prematurely for any possible causes. Thanks to Rob for his Workaround for WordPress database error: [MySQL server has gone away]. The problem has been solved and now my WordPress works [...]

  168. [...] Workaround for WordPress database error: [MySQL server has gone away] for different versions of WordPress By daveamun Workaround for WordPress database error: [MySQL server has gone away] for different versions of Word…. [...]

  169. [...] as few websites already explained how to solve this problem. The first blog that I stumble upon is Robsnotebook, where he explained details on how to fix this [...]

  170. [...] timing out prematurely. You’ll see this on shared hosting services a lot of times. I found a great post on robsnotebooks.com that shows how to do this and even provides a way for WP to automatically reconnect to the database [...]

  171. Danielon 04 Jun 2010 at 4:04 pm

    Wonderful. Last time I re-installed it all. This time a wp-db refresh was all needed. Fantastic!

  172. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  173. ??? » Blog Archive » WordPress ????on 13 Jun 2010 at 7:17 pm

    [...] ?? WordPress ????????????????????????????????????????????????? MySQL ?????????????????????? [...]

  174. [...] timing out prematurely. You’ll see this on shared hosting services a lot of times. I found a great post on robsnotebooks.com that shows how to do this and even provides a way for WP to automatically reconnect to the database [...]

  175. waseemon 21 Jun 2010 at 10:08 am

    My hosting provider is suspend my account due to many mysql connection. Please help me and how to resolve it. Thanks

  176. Jim Eon 09 Jul 2010 at 8:52 am

    Any chance you might make this into a WordPress plug-in so the base code doesn’t need to be modified?

  177. Kojejeon 17 Jul 2010 at 1:26 am

    Wow.. you detailed explain it…
    Thanks for this great post :)

  178. Rajaton 20 Jul 2010 at 9:40 am

    Hey, What about wordpress 3.0 :D

  179. Matthew Tommasion 29 Jul 2010 at 12:15 am

    Can you *please* update this post to include WordPress 3.0?

    I applied this workaround to WP 2.9.2 and it was working fine..

    When I upgraded to WP3.0 the “WordPress database error MySQL server has gone away for query..” has returned, and this workaround no longer works..

  180. [...] using Google, I eventually found this brilliant article at Rob’s Notebook called “Workaround for WordPress database error: [MySQL server has gone away] for different versions of Word…” that provides the workaround for this [...]

  181. Brett Bumeteron 05 Aug 2010 at 1:37 pm

    would also love to get some information on this for WP 3.0.

  182. [...] timing out prematurely. You’ll see this on shared hosting services a lot of times. I found a great post on robsnotebooks.com that shows how to do this and even provides a way for WP to automatically reconnect to the database [...]

  183. kgon 31 Aug 2010 at 12:19 pm

    Excellent! Also your genius action was to include the original files with each workaround. By being able to do a diff between said files means one is able to see your changes and specifically how to build on this for a 3.01 workaround, thank you for this time saver :-)

  184. [...] La solution à ce problème a été abordée dans cet article. [...]

  185. [...] timing out prematurely. You’ll see this on shared hosting services a lot of times. I found a great post on robsnotebooks.com that shows how to do this and even provides a way for WP to automatically reconnect to the database [...]

  186. [...] is another article here that offers different solutions to this problem, although I could not find any solution for WP [...]

  187. Huzon 03 Oct 2010 at 10:31 pm

    Fixed. I was using v2.9.1 when i had the problem. Upgrading to 3.0.1 didn’t solve it. I uploaded the 2.8 workaround to it and its solved! Thanks! :p

  188. [...] dans votre interface d’administration. La solution à ce problème a été abordée dans cet article. Évidement ce problème existe bien mais la solution suggérée ne fonctionnera que si vous mettez [...]

  189. house washingon 21 Nov 2010 at 6:22 pm

    For some hosting, installing wordpress has been their problem because of the errors they continuously receiving. I am glad that you pointed out different points here so wordpress users can easily determine what’s wrong with their installation.

  190. Green Complexon 24 Nov 2010 at 4:53 pm

    I’ve got this problem with 3.1 and I couldn’t get the db.php to fix it, it just knocked all my blogs offline… :(

  191. [...] reference: Workaround for WordPress database error How to fix “MySQL server has gone away” (error 2006) [...]

  192. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  193. Sarasota Homes for Sale | MySQL erroron 23 Feb 2011 at 1:36 pm

    Rob -
    Thanks for you help in this fix. Any idea on when we can expect a fix for WP 3.0+??
    Thanks again for your help towards the community

  194. Roderickon 29 Mar 2011 at 10:57 am

    Thanks for the fix Rob, I will be testing this against one of my websites, that was fine (or I didn’t notice this problem before) until 2 days ago.
    I have no idea why now this website is showing the mysql gone away problem, I’ll uninstall every plug-in and keep testing.

    It would definitely be nice to have a fix for WordPress 3.1, the wp-db.php file has changed a lot since this fix, and is difficult to make out what and where to change it.

    If you found a solution for newer WP sites, please post it here.

    Cheers,
    Roderick.

  195. Anonymouson 23 Apr 2011 at 8:04 am

    Yes, 3.1 fix would come in handy :)

  196. hurrtzon 07 May 2011 at 12:43 pm

    Hey,
    just wanted you to know that I have found another reason for this behaviour to happen: Especialy on hosted websites you will find a rather small database-size. 100mb in my case for one database. When more data is written into the database than the hoster is providing you, wordpress might (or in my case will) show anywhere on the page those mysql-statements including errors of all kinds. The problem was semmelstatz. It gathered so much data that the table wp_statz alone had 160mb. I truncated the table and the problem was gone.

    So, before you do anything critical or something that might take a lot of time: Check out your available database-size and weather your tables are going out of bounds…

  197. Fasteleon 07 Jun 2011 at 7:28 am

    Has anyone found a solution to this problem on WordPress 3.1?

  198. Robon 07 Jun 2011 at 8:26 am

    I’ve got the solution on WordPress 3.1, just email me at wpmysql at(@)robsnotebook.com and I’ll tell you my fee.

    Remember that this is a workaround. The real problem is that your mysql server is taking too long to respond. This workaround just makes your WordPress wait longer for the mysql server to respond. This workaround does not make your mysql server faster.

  199. [...] Workaround for WordPress database error: [MySQL server has gone away] Relaterade inlägg :How do I import a MySQL dumpfile into my database?Optimizing MySQL – Queries and IndexesUsing PHP Objects to access your Database Tables (Part 1)mysql update from another tableMySQL :: Re: Problems in building 1.2.2 on Mac OS 10.5By Blogsdna [...]

  200. [...] I got it working in the end by applying this patch. [...]

  201. Tim Bidenon 04 Aug 2011 at 2:06 am

    “The real problem is that your mysql server is taking too long to respond. This workaround just makes your WordPress wait longer for the mysql server to respond. This workaround does not make your mysql server faster.”

    So if mysql is taking too long, we should apply the workaround only long enough to get the database backed up then get mysql fixed. Since Google is using page load times as a ranking factor, this issue could give a site’s ranking a demerit.

    Thanks for the info and I think I’ll look at the server and my db backups first.

  202. Huzefaon 14 Sep 2011 at 12:01 am

    Hello ROB,

    I was hoping you can also help me out with this error :

    Internal server 500 Error

    Do we have any workaround for this ? And what is the reason behind this error ?

  203. Onlinekredite günstigon 26 Oct 2011 at 4:14 am

    I have same problem with WP 3.1.1. My mysql is fast, much ram, optimized settings. I only have this in WP and currently only with one plugin which parses feeds. I don’t know how to solve it.

  204. Onlinekredite günstigon 26 Oct 2011 at 4:41 am

    I found my solution, I just raised like described above wait_timeout and also interactive_timeout.

  205. [...] This WordPress database error appears on certain configurations and it manifests in very slow and no response, usually on your admin pages. Workaround for this MySQL problem has been best addressed in this article. [...]

  206. [...] depois de debugar descobrir que havia alguma coisa errada no SQL, então eu descobrir neste link como resolver esse problema que é recorrente desde as versões antigas do WP, mas é lógico como [...]

  207. [...] La Solución para este problema de MySQL se intenta abordar muy bien en este artículo. [...]

  208. [...] La Solución para este problema de MySQL se intenta abordar muy bien en este artículo. [...]

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.