WordPress database error: [MySQL server has gone away]
-
I have encountered this error several times in the last 5 months on GoDaddy servers. Each time, GoDaddy has blamed WordPress.
https://totalphysiqueonline.com/ was working just fine with 2.04-2.07 with the exception of the 3, now 4, [MySQL server has gone away] instances.
Why is GoDaddy telling me the problem is with the template or with WordPress?
-
I’m not a huge fan of GoDaddy hosting, but this message:
The error that you are receiving indicates that your MySQL Queries are taking an excessive amount of time and are timing out.
essentially means that whatever you’re running on your blog (including plugins) is taking too long to run and so “times out”. This could very well be how WP is set up on *your* site or could be plugins; who knows.
Can you check the wait_timeout of the MySQL server? If it’s too low then this can happen. By default it’s set to 8 hours.
I just thought I’d make my first contributions to this topic because believe me I’ve been dealing with it for two weeks straight and this is a VERY common problem, the downside for some odd reason is that the proper fix is almost impossible to find, basically what I did was find a way to fix it myself.
You see when we are building plugins for this we obviously may want our plugins to be distributed among a large amount of people so changing the wp-db.php file is just not a very smart move you see I too am using GoDaddy and the error “MySQL server has gone away” is not caused by GoDaddy and its not caused by WordPress.
Its caused by MySQL, some call it a bug but 9 times out of 10 I find that its caused because you are using WAY too many queries, for instance if you have a query inside of a loop then your asking for trouble with this error, my instance required me to have an insert statement inside of a for loop and that loop/insert statement had to run between 30 and 100 times.
Not very economical running the same query over 100 times (Different info being added each time), now what happens here is that you flood the MySQL database, it simply cannot keep up with the amount of queries your sending it so it times out and doesn’t automatically re-connect since most times the re-connect features is on your hosting account and since we don’t have access to the .ini files we have to slow down on the amount of queries being sent at any one time.
So if your running lots of queries inside of a loop try using the sleep(2); statement after you run your query, what this will do is put your code on hold for 2 full seconds after which it will continue, 2 seconds is more then enough time for the MySQL database to catch its breath and insert the information before taking on another query.
The only downfall with that is it makes your script run even longer, so if your looping through 50 or 100 times your loop is going to take about 100 to 200 seconds which is 1.5 to 2 minutes long, that is just crazy and way too long but if your not doing that many queries maybe do the calculations and if it won’t take that long then try the sleep(2); trick.
At least with this method it can be done inside of your code and you don’t have to get the end user trying to do any PHP editing because in my experince most people that use plugins don’t know how to code and asking them to make additional edits to their software usually doesn’t work out to well for the un-savvy computer user.
I’ll get back on this topic with more soon.
Brass tacks:
– I am NOT using GoDaddy; I am using BlueHost.
– This problem has just started within the past two weeks.
– It was happening with 2.2.1 and now it is happening with 2.2.2
– I used the Fix Database plugin and the first time I did it, there were a couple of sites that said something about two users leaving tables open.
– I ran the FixDatabase a couple more times and it fixed that problem, but the main problem is still occurring.
– The problem may be what minidak03 was referring to, but I haven’t changed anything on my sites to start creating these database looping problems.I’m not sure my post will help anyone, but I had to add my voice to the chorus. Please help…
Please help. I opened my database and did nothing, but now my site won’t work. I get this error:
WordPress database error: [MySQL server has gone away]
SELECT * FROM wp_posts WHERE (post_type = ‘page’ AND post_status = ‘publish’) ORDER BY menu_order, post_title ASCWordPress database error: [MySQL server has gone away]
SELECT DISTINCT YEAR(post_date) ASyear
, MONTH(post_date) ASmonth
, count(ID) as posts FROM wp_posts WHERE post_type = ‘post’ AND post_status = ‘publish’ GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESCWordPress database error: [MySQL server has gone away]
SELECT * FROM wp_categories WHERE cat_ID > 0 AND link_count > 0 ORDER BY cat_name ASCAnd this is the reply from mysql.com
“This is an error coming from WordPress you will really need to call on them to get support. We know MySQL but we don`t know how it is used within WordPress”
Please help.
CarolIt seems to be in my template. Don’t bother helping. Thanks.
I’m not an expert, but wanted to add my experience to this thread. It seems to confirm what everyone else is saying.
I’m running WordPress 2.3. I have had no problem. Yesterday I added a news aggregator to my site (Gregarius). This morning I started getting the WordPress database error: [MySQL server has gone away] error when trying to view my site. Gregarius uses its own database, so I made no changes to my WP installation or its DB.
My host increased my PHP memory limit and resolved the issue, at least so far.
From reading here it seems that even though I did nothing to WP, after adding the aggregator mySQL was getting overwhelmed during updates. If I continue getting the error the first thing I’ll do is disable Gregarius. If that seems to solve the problem I’ll look into adding the 2 second wait into the aggregator’s code.
I just want to add that I never had this error before, but after upgrading to 2.3.2, I have it all the time. Here is what happens when I post:
WordPress database error: [MySQL server has gone away] SELECT a.user_id FROM wp_usermeta AS a INNER JOIN wp_usermeta AS b ON a.user_id = b.user_id INNER JOIN wp_usermeta AS c ON a.user_id = c.user_id INNER JOIN wp_usermeta AS d ON a.user_id = d.user_id WHERE a.meta_key='s2_subscribed' AND b.meta_key='s2_format' AND b.meta_value='text' AND c.meta_key='s2_excerpt' AND c.meta_value='post'AND (d.meta_key='s2_cat8' OR d.meta_key='s2_cat16') WordPress database error: [MySQL server has gone away] SELECT a.user_id FROM wp_usermeta AS a INNER JOIN wp_usermeta AS b ON a.user_id = b.user_id INNER JOIN wp_usermeta AS d ON a.user_id = d.user_id WHERE a.meta_key='s2_subscribed' AND b.meta_key='s2_format' AND b.meta_value='html'AND (d.meta_key='s2_cat8' OR d.meta_key='s2_cat16') WordPress database error: [MySQL server has gone away] INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('473','_pingme','1') WordPress database error: [MySQL server has gone away] INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES ('473','_encloseme','1') WordPress database error: [MySQL server has gone away] UPDATE wp_options SET option_value = 'a:3:{i:1200844883;a:1:{s:8:\"do_pings\";a:1:{s:32:\"40cd750bba9870f18aada2478b24840a\";a:2:{s:8:\"schedule\";b:0;s:4:\"args\";a:0:{}}}}i:1201396983;a:1:{s:17:\"wp_db_backup_cron\";a:1:{s:32:\"40cd750bba9870f18aada2478b24840a\";a:3:{s:8:\"schedule\";s:6:\"weekly\";s:4:\"args\";a:0:{}s:8:\"interval\";i:604800;}}}s:7:\"version\";i:2;}' WHERE option_name = 'cron' WordPress database error: [MySQL server has gone away] SELECT post_content FROM wp_posts WHERE ID = '473' WordPress database error: [MySQL server has gone away] UPDATE wp_posts SET post_parent = 473 WHERE post_parent = -1200844329 WordPress database error: [MySQL server has gone away] SELECT * FROM wp_posts WHERE ID = '473' LIMIT 1 Warning: Cannot modify header information - headers already sent by (output started at /home/huffengl/public_html/wp-includes/wp-db.php:176) in /home/huffengl/public_html/wp-includes/pluggable.php on line 391
My posts always seem to post just fine, but I would like to fix the error.
Loads of this problem even with 2.3.3. The hacked wp-db.php is hardly a solution. It doesn’t work. I cannot (and should not need to) change my mysql timeout value, which is quite high anyway. When is WP going to become a well-coded solution?!!
- The topic ‘WordPress database error: [MySQL server has gone away]’ is closed to new replies.