Thought and Freedom

Articles for those who think. By Terry Pearson

MySQL Server Has Gone Away problem solved

with 10 comments

I was just looking at RobsNotebook.com and came across a really good solution to a common problem with WordPress.

Lately, I have been getting a lot of error messages on my blog that said “MySQL server has gone away.” I looked through the Godaddy support forums hoping to find a solution. Unfortunately, I did not.

But then I found RobsNotebook.com and they had a page dedicated to this problem. It turns out that it is caused by the SQL connection being open for too long. Essentially, WordPress does not close the connection every time.

Godaddy’s (or insert your own host here) configuration of MySQL tells it to time out after a certain period, and that can happen in the middle of your call to the database.

RobsNotebook.com has provided a php file that you use in wordpress and just replace your existing file. He made it so easy that it takes only about 5 minutes to put in the solution.

P.S. I verified that the php page was correctly coded and had no “funny business” on it, but as the file could change at any time, it is always good to look through it for yourself whenever you download and use PHP from the net.

Related posts:

  1. Wii have a problem! It has been a little less than a month since the Wii and the PlayStation 3 were released. My initial reaction was that I would definitely choose the PlayStation if...
  2. SQL Statements – Create a database As mentioned in earlier posts, SQL is an extremely important part of web development. Below is instruction on how to create a database in SQL. This is based on a...
  3. Testing your Domain Name Server I recently transfered all my domain names to a new hosting provider. In the process of moving the domains, I forgot to change some of the domain name server info,...
  4. Getting Your Own Domain Name This weekend I was able to help set my dad up with his own websites. Rather than build his own server (as I have done), we took the simpler route...

Written by Terry Pearson

February 29th, 2008 at 11:48 pm

10 Responses to 'MySQL Server Has Gone Away problem solved'

Subscribe to comments with RSS or TrackBack to 'MySQL Server Has Gone Away problem solved'.

  1. At least you didn’t have my mySQL problem (that sounds strange!) I had a silly plugin that got spammed and then decided to query all the spams, 50k rows at a time! :(

    You can guess how my host reacted!

    Like or Dislike: Thumb up 0 Thumb down 1

  2. yo,im also on godaddy
    and i must say that error (sever has gone) when running longer sql queries really pissed me off.
    though,the solution seems to be to mysql_close() the connection before it exceeds the time limit what actually probably causes godaddy service to close the connection itself.
    but what i just recently noticed is,
    check out Mysql Proccesslist on Godaddy MYSQL Servers,
    you will see the port changes,that could be one reason why it says “Server gone”.
    so each time you close the connection and estabilish a new one it catches the new port(which could have changed in an interval of max time).
    So there are 2 theories:

    1.Godaddy simply set a quite short maximum of connection time. : Workarround => mysql_close();
    2.Godaddy changes port in an unknown interval(would need some research to find it out). : Workarround => mysql_close();

    Maybe mysql_free_ressources also can help a bit,but i dont think so(just give it a try :)

    so the final solution seems to be to close the godaddy mysql connection as fast as possible.

    close,connect … probably wont cause your server to crash(not really similiar to DOS) so no worries!

    Like or Dislike: Thumb up 0 Thumb down 0

    yo

    21 Aug 08 at 08:48

  3. It works for me.
    Thanks alot.

    Like or Dislike: Thumb up 0 Thumb down 0

    mine

    21 Oct 08 at 17:26

  4. So, what’s the configuration option that needs to be changed to solve this problem?

    Like or Dislike: Thumb up 0 Thumb down 0

    iGuide

    17 Sep 09 at 13:47

  5. I have 100 domains on Godaddy and i can say that this company is very reputable.”-.

    Like or Dislike: Thumb up 0 Thumb down 0

    Brooke Morris

    5 May 10 at 01:45

  6. I have the same problem hosting on godaddy, though using druapl install. So I can’t use your total fix. But I’m hoping that I can get some tips from what you’ve done.

    Are you essentially saying that I need to call mysql_close after every database request that my site makes? Or do I need to call it explicitly when my page has finished generating?

    Like or Dislike: Thumb up 0 Thumb down 0

    Imran

    19 Oct 10 at 08:15

  7. Imran, check out the comment by “Yo” on this post. I think his theory about random port changes is correct.

    I would say you could probably close the connection at the end of the page load. The most important thing is that you do not want to have an open connection through a port that has been changed randomly by GoDaddy. So if “Yo’s” theory is correct, you should be fine with closing the SQL connection at the end of a page load.

    Like or Dislike: Thumb up 0 Thumb down 0

    Terry

    19 Oct 10 at 09:32

  8. Actually the problem with GoDaddy servers and most others having this problem is quite simple to fix if you have root access to the server. Clear everything out of etc/my.cnf and replace with

    [mysqld]
    set-variable = max_connections=500
    safe-show-database
    query-cache-type = 1
    query-cache-size = 20M

    Then restart sql.

    The “MySQL Server Has Gone Away” issue will… well… go away.

    Like or Dislike: Thumb up 0 Thumb down 0

    William Johnson

    18 Dec 10 at 08:29

  9. I ran into this same error this morning. The resolution was just restarting our MySQL service on the service and the error went away immediately.

    Like or Dislike: Thumb up 1 Thumb down 0

    Sandcarving

    5 Sep 11 at 11:24

  10. Good point Sandcarving. If you have a dedicated VPS or Server, you can do just that. You can also adjust the timeout settings at that point.

    However, if you are on a shared host, the problem is probably not a failure of the MySQl server, it is just a timeout issue, of which you have no control in a shared environment.

    Like or Dislike: Thumb up 0 Thumb down 0

    Terry

    6 Sep 11 at 13:29

Leave a Reply


Creative Commons License
Terry Pearson - The Blog by Terry Pearson
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.