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.