WordPress Database Error MySQL Server has Gone Away

By LaurenMarie

Update: The problem has been solved! Read about the solution.

I politely asked the MySQL server to come back, but it refuses.

You’ve probably noticed a few posts and comments missing. I’m having trouble with Wordpress and you’ve also probably noticed that, too: when you comment on a post, it takes you to a 404 page. After a lot of fruitless research and 5 calls to my host, I had to have them try one last thing… rolling the account back to before when the error occurred. That didn’t help! So now I’m pleading with you, if you can think of anything, please let me know!! Short of completely deleting the DB and files and reinstalling WP, I don’t know what to do (and I had a tough time importing the DB when I moved over to my new host 2 weeks ago).

Below is the thread I started at Wordpress Support. I’m asking you to help, too.

I have been dealing with a strange issue for the past two days. I hope I can give enough explanation so you have an idea of what is going on. I would be so greatly indebted to you if you could help me!!

I am getting the above error when someone comments on my blog (WordPress database error MySQL server has gone away). It brings up a 404 error page and the address displayed in the address bar says wp-comments-post, which makes me guess that’s where the error lies. If I am logged in as the admin and post a comment, it brings up a 500 error, again with the wp-comments-post. It really seems like it’s a problem with the redirect, but I’ve downloaded the wp.zip file and taken a fresh file out of there and uploaded it. Nothing.

The comment IS posted to the database and if you click the back button, the new comment is now at the bottom of the page.

I hadn’t changed anything in the settings or files from the time it was working to when it stopped working. I did have a scheduled post that went up, but other than that and some comments, no change to the database either.

Fixes I’ve tried:

-updating to WP 2.5.1
-updating all plugins
-deactivating plugins one by one to see if they are causing the problem
-replacing wp-db (but the one on OpenAdvent doesn’t work for 2.5+ and gives me an error… won’t even load the site!)
-deleting and reuploading the .htaccess file
-rolling back the server to when before the problem occurred (VERY weird that this didn’t fix it! And I’m back to 2.5 now)
-replacing the wp-comments-post file
-Bluehost performed an SSH test to determine that the DB is functioning as it should
-updated permissions on wp-comments-post to 755

UPDATE: I received this from my host this morning. I don’t know that it helps too much, though. See if it gives you any ideas…

There are a couple of reasons why this might happen, but let me explain what is happening first. When a MySQL connection lies idle on the server for more than 60 seconds, our servers disconnect it. This is to prevent excess server load, and to release the connection socket back into the pool to prevent connection failures.

There are a couple of reasons that this might happen. The more common is that your script opened a MySQL connection, and then began doing other things, like uploading a file via FTP. Some of these actions can take a while, and so the script goes idle until it receives an awake call telling it that the action completed. While this is good for continuity with the script, the MySQL connection is closed causing problems. Basically, this is a problem with script design, and the developer of the script would need to resolve this.

The other common reason for this happening is Persistent MySQL Connections. This would be a setting in your script. Essentially what this is designed to do is speed up the connection of a MySQL database to a script by not allowing the connection to close. The problem with this is that, even according to MySQL, it does not significantly speed the connection process, and on our servers, the connection is closed long before it is needed the second time. The resolution of this issue would be to disable persistent connections for the MySQL database. Contact the script developer for assistance in doing this.

PLEASE if you have any ideas, let me know so I can try them!

One thing I noticed is that if you are the first one to comment, it goes through and reloads just fine. Let me know if you DON’T experience the 404 redirect when you comment. If you do experience it, just hit the back button or reload the post to see your comment.

  1. Posted May 2, 2008 at 12:17 am | Permalink

    Let’s see how this works…

  2. Posted May 2, 2008 at 12:18 am | Permalink

    All good for my first comment, and if you don’t hear from me after this second one, it’s good for it too.

    I can empathise with the issues you’re having. Hope you get them all sorted asap.

  3. Posted May 2, 2008 at 1:24 am | Permalink

    Test comentario

  4. Posted May 2, 2008 at 1:24 am | Permalink

    It “seems” you’re okay.

  5. Posted May 2, 2008 at 1:27 am | Permalink

    I did get a couple of 500 errors when I was commenting on your blog recently, but I figured the server was just having a hiccup trying to connect. Also, the network at my uni is pretty unreliable.
    I’ll keep thinking about it and let you know if I have any ideas…

  6. Posted May 2, 2008 at 4:08 am | Permalink

    wp-comments-post adds the new comment and then redirects back so the problem is at least in a well defined section.

    Yo ushould first make sure that your urls are correct in the settings. It could be it is trying to redirect somewhere that doesn’t exist, like a subfolder.

    If you haven’t already tried it I would disable every plugin, including Akismet, and enable them again. Anti-spam plugins typically get involved at the point you are having problems with.

    If all that fails and you still have a problem and no one else can tell you what is wrong drop me an e-mail and I will try and help you when I’m home this evening.

  7. Posted May 2, 2008 at 4:09 am | Permalink

    No 404 on that comment.

  8. Posted May 2, 2008 at 5:35 am | Permalink

    You probably already hit google, but just in case, I ran across this article:

    http://robsnotebook.com/wordpress-mysql-gone-away

  9. Posted May 2, 2008 at 6:46 am | Permalink

    All seems OK for me. Edit: No I got the 404 this time.

    Have you tried installing a new wordpress and installing your old mysql there? Does it have the same problems?

    Also I would probably update your 404 page just for now telling ppl about the problem and that their comment did work.

  10. Posted May 2, 2008 at 7:02 am | Permalink

    Wow, guys thanks sooo much for your support and concern and solution ideas. It means a lot.

    So now it looks like it’s only happening intermittently instead of every single time. I guess that’s an improvement!

    Andrew,
    Yes, I scoured that wp-comments-post and figured out how it’s getting the redirect page (which is essentially reloading the page commented on with the new comment) and it seems like it should work. But I had not thought about the spam part. I have tried going through each plugin and disabling it and nothing changed. You gave me a couple more ideas, though, and I’ll try them out. Thank you for your offer to help! I’ll let you know.

    Alec,
    Yes, I saw similar solutions about the wp-db and I did replace it. Now than you mentioned it, I remember doing that. But I can certainly try again! I’m desperate at this point! But thankfully the blog is still basically working.

    Jacob,
    I haven’t tried installing a new second WP with the current db. That’s a good idea! So is updating the 404… Thank you!

  11. Posted May 2, 2008 at 7:03 am | Permalink

    Hmm, and my comment didn’t get a 500 error that time… that’s good, too!

  12. Posted May 2, 2008 at 7:05 am | Permalink

    testing.. got the 404.

    But I don’t undestand the redirect to wp-comments :-/ Well gotta make some more test, time to install WP yet again.

  13. Posted May 2, 2008 at 7:07 am | Permalink

    Oops, sorry Esben. I was monkeying with something just as you were commenting… did you get an error?

  14. Posted May 2, 2008 at 7:12 am | Permalink

    testing once again :-(

  15. LaurenMarie
    Posted May 2, 2008 at 7:13 am | Permalink

    This is a test from me, but I’m not logged in as the Admin….

  16. Posted May 2, 2008 at 7:18 am | Permalink

    I get the error, but I don’t “get” the redirect ;-)

  17. Posted May 2, 2008 at 7:24 am | Permalink

    Yeah, so I still get the error when not logged in as Admin, but the Admin comments seem to be working now. The problem with this is that you try so much stuff, you lose track of what worked!

    ok… I got a 404 logged in as admin that time. GAH!!

  18. Posted May 2, 2008 at 7:31 am | Permalink

    test

  19. Posted May 2, 2008 at 1:07 pm | Permalink

    Hm, I don’t see how their response to you makes much sense for the specific problem that you are having.

    I’ll do my part of digging and see if I can find any useful hints or common problems (although I’m sure you’ve done the same).

    Hope everything is ironed out soon!

  20. Posted May 2, 2008 at 1:41 pm | Permalink

    Jacob Carter,
    The host’s response does make some sense actually because WP opens up a connection to MySQL and keeps it open while transfering data. If there is too long of a gap (a script may be stuck in an infinite loop, a file may be uploading or something) then the host closes the connection to avoid too much CPU load for my acct.

    The link that Alec provided can help fix when a script fails to connect by reconnecting, which is actually something I think WP should include automatically in their wp-db file. After installing that and checking my Error Logs, I’m not seeing the specific “MySQL has gone away error” but commentors are still sometimes getting the 404 instead of a refreshed page.

    *sigh* so now I don’t know what’s going on. But thank you for your offer to help! I really appreciate it and do please let me know if you find anything!

    Did you get a 404 when you submitted your comment??

  21. Posted May 2, 2008 at 6:15 pm | Permalink

    My comment submitted just fine. *shrug*

  22. Posted May 2, 2008 at 11:09 pm | Permalink

    I’m sorry to read that you’re still having issues with the blog on the new hosting server. Let’s see what it does with my comment.
    It worked fine – no problems, and I’m editing this with AJAX Edit comments plugin

  23. Posted May 3, 2008 at 8:39 am | Permalink

    Vivien,
    I think I may have fixed it but I’m not entirely sure yet… I replaced a few files that I had modified a long time ago. I didn’t think it could be them because they’ve been working just fine for about 3 months. But I tested it a few times last night and things looked ok.

    I actually think it was a combination of those files and a MySQL timeout (resulting in the “gone away” error). I replaced the wp-db file with the one provided in Alec’s link. That’s when the problem started occurring intermittently. Then I replaced the modified files. So we’ll see… it seems to only be happening to about half the people commenting.

  24. Posted May 3, 2008 at 6:15 pm | Permalink

    Could it have anything to do with the Ajax comments? Did you update that one before or after the problem? The difficulty with this problem is that it’s only happening some of the time, so you could deactivate a plugin and maybe just miss an instance where it happens… if you get my drift. My comment worked fine before. Lets see how it goes now.

    Edit: worked fine.

    Edit: I don’t get the title of this post. Has the error disappeared?

  25. Posted May 3, 2008 at 6:25 pm | Permalink

    Oops, just read your comment to Vivian :)

  26. Posted May 4, 2008 at 3:19 pm | Permalink

    Kristarella,
    No, it’s not Ajax Edit Comments. I disabled and then completely uninstalled (deleted from server) it and the problem was still occurring. Yeah, I wish it would either happen all the time or never, it’s hard to find a problem when it doesn’t seem to happen consistently! You would think with the way a computer works a problem would either always or never happen. I’m glad your comment worked ok. Let’s see if mine does now…

    Yup, worked fine.

  27. Posted May 4, 2008 at 4:12 pm | Permalink

    Hey Lauren, sorry to hear about the recent probs. I can relate… my feed decided to die (without telling me) and none of my trouble-shooting has worked! Don’t you just love spinning your wheels when that happens?

  28. Posted May 4, 2008 at 4:26 pm | Permalink

    Charity,
    Ugh, yeah, I wish technology would just work the way we want it to! I was about to say “the way it should” but a computer only does exactly what we tell it to… they shouldn’t take things so literally all the time :P

    Have you tried deleting and redoing your feedburner feed? I’m sure most people will just ignore all the new entries. What about FeedSmith? Think it could be a problem with that plugin? Oh wow!! And you rebooted your blog! Looks great!

  29. Posted May 4, 2008 at 5:39 pm | Permalink

    Thanks Lauren – didn’t mean to use your blog as a vent, but I really appreciate the quick response you sent! Everything seems to be working fine now since I rebooted. Not sure what the deal was but I’m checking it off the list… for now. :)

  30. Posted May 4, 2008 at 6:03 pm | Permalink

    Charity,
    Don’t even worry about it! I didn’t see it that way. I’m glad everything is sorted out for you (and for me too!! I’ll write an update post on my issues in a bit… well, at least the blog related ones!)

Creative Curio design by LaurenMarie and built on the Sandbox theme. Copyright 2007-present. Proudly powered by WordPress and BlueHost.