I've just downloaded a drupal site I'm working on which functions perfectly on the live server.

But on my local machine every query gives the "MySQL Server has gone away".

I'm good with drupal (definitely not a n00b) but not so good with servers so I have very little clue as to what could be causing this. I've read the MySQL docs on the error without enlightenment, read all the drupal references to it. No help there.

I believe I have the usenames and passwords set-up right because drupal tries to display the front page but in doing so I'm getting 50-60 of these errors, apparently one for every attempted MySQL query.

Warning: MySQL server has gone away query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>MySQL server has gone away\nquery: UPDATE cache_views SET data = &amp;#039;a:4:{s:6:\\&amp;quot;tables\\&amp;quot;;a:166:{s:17:\\&amp;quot;nodefamily_parent\\&amp;quot;;a:3:{s:4:\\&amp;quot;name\\&amp;quot;;s:10:\\&amp;quot;nodefamily\\&amp;quot;;s:4:\\&amp;quot;join\\&amp;quot;;a:3:{s:4:\\&amp;quot;left\\&amp;quot;;a:2:{s:5:\\&amp;quot;table\\&amp;quot;;s:4:\\&amp;quot;node\\&amp;quot;;s:5:\\&amp;quot;field\\&amp;quot;;s:3:\\&amp;quot;nid\\&amp;quot;;}s:5:\\&amp;quot;right\\&amp;quot;;a:1:{s:5:\\&amp;quot;field\\&amp;quot;;s:10:\\&amp;quot;parent_nid\\&amp;quot;;}s:4:\\&amp;quot;type\\&amp;quot;;s:5:\\&amp;quot;inner\\&amp;quot;;}s:7:\\&amp;quot;filters\\&amp;quot;;a:1:{s:9:\\&amp;quot;child_nid\\& in C:\wamp\www\includes\database.mysql.inc on line 172

The error is being triggered in the _db_query function, not really a surprise, so essentially every attempt to run a query says the server has gone away (although it's still there).

Also attempting to access any other page generates a 404 Page not found (even admin).

I went into the system table and switched off the Dev and Watchdog modules (maybe not the greatest idea) and also removed the dev variables to stop the debugging part. But it made no difference anyway.

I'm wasting time trying to get this running when I should be developing code. Any ideas?

Steve

Comments

tm’s picture

try searching drupal.org for the string "MySQL server has gone away" (with the quotes). hopefully someone else's solution will be yours, too.

not being sarcastic, really. just that everyone's situation is just, well, different.

added: just thinking about it; you are trying to migrate a prod install to local. you are not even getting far enough to get "white screens". the error indicates nodefamily might be a part of it? can you get to the database via phpmyadmin? wonder if you can temporarily disable that module.

sorry, lost track of the handbook page on moving between servers; one of the steps was to clear the cache. also assuming that space is not an issue. you may wish to disable local antivirus until things get going (overhead); disconnect from the world if you do that.

SteveTurnbull-1’s picture

(I'd already read everything on the drupal website about this error -- no help.)

OK, a small part of the problem was that the .htaccess hadn't downloaded, that's why I couldn't access any other pages. But no I'm not getting white screens -- they wouldn't scare me :-)

What I'm getting is pages full of "MySQL server has gone away" because that's what every query is generating.

Yet Drupal doesn't say it can't find the server, which you'd expect if the username, password or database names were wrong. For example (using MySQL administrator) I remove all the privileges for Drupal, I get the start-up error saying that drupal can't access the database, if I give it the privileges back then it happily generates a hundred "MySQL server has gone away".

I have cleared all the caches. Antivirus is not an issue (this machine is isolated from the web.)

FIXED. SEE BELOW....

tm’s picture

whatever made you look at that as a solution (indicators)? hints?

good that you got it going, in any case.

added: were you looking at http://dev.mysql.com/doc/refman/5.0/en/gone-away.html as a troubleshooting reference?

awilliams’s picture

I added: max_allowed_packet = 64M to my.ini and it solved the probems

opdavies’s picture

Worked for me. :)

Anonymous’s picture

I had this server gone away problem with help / token. Your solution worked for me, thanks!

sarnzzle’s picture

Thanks for the tip, got it working with this!

siddhesh.blisstering’s picture

thanks! it worked..

pokepasa’s picture

It worked for mee too. Thanks.

dnmurray’s picture

The interesting part was this just cropped up out of nowhere (old max was 2M). A cache_views update statement suddenly started failing. Of course, everything after that goes down with it.

bhupendra_kanojiya’s picture

perfect.....Thanks

silverhair2010’s picture

Thanks

ressa’s picture

I inserted

[mysqld]
max_allowed_packet = 64M

in /etc/my.cnf and restarted MariaDB:

systemctl restart mariadb
Corey Smith’s picture

I had the same problem earlier when trying to load the Poormanscron. Once I disabled the module, problem went away.

Corey Smith

SteveTurnbull-1’s picture

Thanks but we're not using poormanscron.

SteveTurnbull-1’s picture

Fairly simple cause: the packet size on MySQL wasn't big enough and since this application uses big queries and masses of data the local version of MySQL just gave up and refused to do it.

In "my.ini" you want:

[mysqld]
max_allowed_packet=24M

(or whatever, I chose a ludicrously big number.)

Steve

askttt’s picture

Could there be an alternate way of fixing the problem. I don't have acces to my.ini with Godaddy.

Purazar’s picture

Same problem here... I'm hosting with Go Daddy as well, and I have no way of increasing the packet size. Any other solutions to this problem?

shyamala’s picture

Tried increaing packet size/wait_timeout wiht no effect. WHen I create a long CCK I get the MySQL gone away error. Have been stuck with this problem for over a week, any help is appreciated.

Summary of the associated my.ini file:

| max_allowed_packet | 1048576
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | D:\server\mysql\Data\meenambica-slow.log
version | 5.1.22-rc-community
| wait_timeout | 28800

Thanks
Shyamala
Team Leader Netlink Technologies Ltd.

g76’s picture

this worked for me. I am on a shared hosting account, no access to mysql settings, but this seemed to fix it:

http://drupal.org/node/227445#comment-770663

also, disable syslog and database logging.

gideon

jeditdog’s picture

are you just using basic drupal functionality at GoDaddy? I ask because I'm there too and you're scaring me :)

I'm wiling to run some tests there if you let me know what it is you're trying to do there.

You're not trying to connect @localhost are you though? My experience is that GoDaddy hosts the DB on a seperate server.

-------------
The main man of MMC :)

lasarletter’s picture

where is my.ini in the drupal system?

tm’s picture

this is not a drupal file. my.ini is the mysql configuration file; it is usually in the root of your mysql installation.

kenorb’s picture

Thanks, it works.

michelle’s picture

I've been struggling with this, too. I ended up setting it to 48 and also putting it in the "client" section and finally the errors went away.

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

japo32’s picture

I'm running on wamp locally. I added the line
max_allowed_packet = 24M

to [wampmysqld], [mysqldump], and [mysqld]

Thanks a lot!

mattrweaver’s picture

I mean it! Thanks!

Finished products are for decadent minds. -- Isaac Asimov

Finished products are for decadent minds. -- Isaac Asimov

jary’s picture

Thanks Steve! Helped me alot!

jcfiala’s picture

Wow, that just saved me a lot of headache! Good job, Steve!

--
-john

dibya’s picture

Thanks a lot. It solved my problem instantaneously.

muhammad.tanweer’s picture

Thank you Steve. This one worked for me. I would like to add a little explanation.

1 - open the my.ini file.
2 - you might not have this (max_allowed_packet) line already there.
3 - So you need to add it at some point in this file.
4 - Save the file
5 - Restart wamp services and you are good to go.. :)

http://www.drupalxpert.com

bajah’s picture

im using xampp, and did a search for the my.ini file and couldn't find it.

Cellarstudios’s picture

Is there a work around for this issue without having to edit root .ini files? I am hosted on Godaddy.com and I too can not reach these files to edit them.

I am getting the same error as listed above.

muhammad.tanweer’s picture

Even on a shared hosting, they give you a php.ini which is specific for you domain. You can edit that and add these lines. Now, it should work but if the service providers do have some limitation (like if they don't allow to increase the packet size from a certain amount), then I think you ll need to go to some other hosting.

Muhammad

SteveTurnbull-1’s picture

Sorry guys, the problem is that Drupal builds *massive* PHP files out of all the separate files.

In fact it can get even worse than this. The problem might not solve by just changing that value, sometimes you have to get into the server because that can override the .ini setting.

Which happened on my latest job.

ahoria’s picture

what would be a good shared host to cope with issues like this?

thanks

SteveTurnbull-1’s picture

One that supplies Drupal as part of its package perhaps.

In the UK I use purleyhosting.com, small company, friendly and they use Drupal themselves.

dale42’s picture

I ran into this problem running XAMPP on a Windows XP configuration.

Increasing max_allowed_packet in the [mysqld] from 1M to 16M (max_allowed_packet = 16M) in xampp\mysql\bin\my.cnf and restarting MySQL solved my instance of the problem. I may have been able to get away with a smaller increase but I didn't experiment.

eighthourlunch’s picture

I set max_allowed_packet to 8M on a Windows 7 XAMPP install in my.ini, and the error went away.

brunodbo’s picture

Had the same problem. Increasing max_allowed_packet didn't help.

Changing the wait_timeout variable in /var/lib/mysql/my.cnf did help. It defaults to 15 (seconds). Increased it to 45, and MySQL didn't go away anymore.

--
Don't hate the media, be the media -- www.indymedia.be

newbii’s picture

I can't find the files in phpmyadmin and ftp. Where can I find my.ini and my.cnf? I use shared hosting.

SteveTurnbull-1’s picture

I'm afraid you probably don't. On a shared host you may be limited. You need to ask your hosting company about it.

Slacky08’s picture

I had this problem and managed to fix it thanks to the following article which gave the same information here, except I didnt know how to do it in XAMPP on Windows XP install.

http://minorpoint.blogspot.com/2007/09/mysql-server-has-gone-away.html

newbii’s picture

I only get this error if I configure the block module. But, when I use faster internet connection to configure the blocks, I don't get this error.

It is a strange effect for me. Please let me know what you think about this.

bigmotard’s picture

FYI

I have my drupal site hosted on HostICan (www.hostican.com) hosting provider (aka HIC). HIC Team refused to change the parameter of mysql 'max_allowed_package' to increase the buffer size between Drupal and MySQL in a shared environment. They forced me to upgrade to a Virtual Private Server hosting package to allow this config modification.

To let you figure out my drupal site resources usage and help you decide which hosting package you will need to hire when using Drupal on HostICan read the following:

- My site has less than 100 registered users.
- My site has never had more than 15 concurrent users.
- My site AWStats say that from June the 1st to June 26th we've had an average of 141 visits per day with a bandwidth consumption of 160MB per day.

Clearly, in my honest opinion, this is a real little Drupal installation. Therefore we can conclude that HostICan is not prepared to host Drupal sites on their Base Hosting package, be careful.

HostICan has a good system technologies environment, but be carefull if you are trying to mount a "real" drupal site on their hosting. If you hire a Base hosting, you will only be able to "play" with drupal...

Regards

P.s: This post is not to make any preasure on HostICan team nor being dissuasive with new HIC users. My only intention is to inform all of you about what you will need to hire if you plan to build a Drupal site on HIC.

graper’s picture

Not that I know the real reason why HIC would not do this, I do know a good reason why any hosting company would not want to increase this on a server devoted to shared hosting.

Most hosting companies that allow for shared hosting accounts just about give away bandwidth and storage space. Seems that you can get account for as low as $5.00 a month and get just gigs and gigs of storage like 300gigs or more, they also give you gigabytes or terabytes of bandwidth each month. From a marketing perspective it's very appealing to a website owner. What truly matters, especially with database driven sites, is CPU cycles and memory. The bigger the database the memory footprint you'll leave, also the same with mode code. Consider drupal, the more modules you enable the bigger the memory footprint as all the code of every module gets loaded and executed. The more code, or even complex looping of code, will take more CPU time. If you have a shared account and try to run more then 50 domains on that account because they say you can have "Umlimited Domains", well guess what, if you start eating too much ram or CPU cycles, they can just kill off your processes. This happened to use on a shared account. We soon realized that almost every hosting company had the same scenario.

While MYSQL documentation says "It is safe to increase the value of this variable because the extra memory is allocated only when needed. " link it still has some impact on ram allocation and therefore a hosting company has to take it into consideration.

The other real reason that they deny this change is that they are in control and want more money out of you for more options :)

Granville
Kirkham Systems

timdp’s picture

Just wanted to say that I have a simple account with Lypha (can't remember how much, but <$10/month). They have always been helpful with raising limits, without suggesting a more expensive account. In this case their reply was:

Hello,

We have made the needful.

- The time limit has been set to 60 seconds
- The max memory allowed is 64M
- The mysqli.reconnect has been set On

Kindly check now.

And it worked.

yuriy.babenko’s picture

Thanks for that tip. I was having the same problem (locally) and this fixed it.

Cheers!
---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

summit’s picture

Still this problem, subscribing how to fix.
I got this problem MYSQL GOES AWAY updating from 5.12 to 5.14.. Anyone else also experienced this?

Greetings,
Martijn

pedrosp’s picture

The way out for this labyrinth for me has been disabling the (helpful btw) Update Status Module.
I ask first to my hosting to enable max_allowed_packet=24M
We've tried also to run mysqli.reconnect = On;
But without good results.
By the way, I'm quite happy with the technical support of my hosting service allowing that fine tuning.

Then I saw this comment: http://acquia.com/node/45684#comments
"Most often when there is slowness related to Update Status it has to do with the server blocking outbound HTTP requests."

It works fine now !! Just Disable the module

My workaround: Drupal 5.14 - Hosted in http://www.sync.es
Update Status 5.x-2.3

summit’s picture

Hi,

I think it is not a solution to disable the update_status module, while it holds valuable information.
So please is it possible to patch update_status so it doesn't need to be disabled anymore?

Thanks a lot in advance for going into this deeply!
Greetings,
Martijn

WorldFallz’s picture

There's nothing in update_status that can be patched if your host is blocking outbound http requests. I had this problem with one host, and the resolution ended up being to switch hosts (they refused to unblock http).

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

lenkkivihko’s picture

This is caused by a mysql max_allowed_packet setting, which by default is set to 1M.

You can confirm the setting by

* checking the value in sql by issuing a show variables command, or
* by checking the system variables in phpmyadmin.

To change the setting, you need to edit the my.cnf file in your c:\...\xampp\sql\bin directory and change the default value of 1M to something larger, for example 16M.

grfiv’s picture

A solution for many of the causes of the error "MySQL server has gone away" is found here: http://www.philadelphia-reflections.com/blog/1503.htm

summit’s picture

Hi,
I tried:

$db_link = @mysql_connect(DB_HOST, DB_USER, DB_PSWD,'',MYSQL_CLIENT_INTERACTIVE);

... instead of what you used to do:

$db_link = @mysql_connect(DB_HOST, DB_USER, DB_PSWD);

And it worked! thanks for your info.
Greetings,
Martijn

shenzhuxi’s picture

It mainly happen on windows because there is not "max_allowed_packet" in the default settings of mysql.
Adding "max_allowed_packet=32M" on my.ini can solve it.

kenorb’s picture

#327066: Warning: MySQL server has gone away: recursive error reporting

Try as well db_tweaks module to increase your max_allowed_packet

btwoodward’s picture

Disabling the update module did it for me. I am using 000webhosting - haven't had any other issues with them.

held69’s picture

setting max_allowed_packet = 24M

on wamp server worked for me

Aurochs’s picture

I also disabled update

But afterwards i got a reply from my Russian hosting hc.ru that i can make it with a php.ini placed in root of my ftp.
It was not making effect until i added foll to .htaccess in the root of my site:

SetEnv PHPRC <path to php.ini>

My webhost allows to increase memory from default 64m to 128m with php.ini means and also increase some other options.
php.ini is present in ftp by default with better options.

summit’s picture

Hi Aurochs, Did you enable update.module afterwards, and it was working again?
Isn't path to php.ini "/" because it's on the root?
Thanks for your reply in advance!
greetings, Martijn

Aurochs’s picture

Hello

php.ini is in the root of my hosting directory

so here is my code from .htaccess

SetEnv PHPRC /home/gamepart/php.ini

my goot hosting directory is /home/gamepart/

gamepart is my acct name

Yes i did enable the update module and it works fine

leo pitt’s picture

I'm on a WAMP system with drupal 6.2, mysql 5, php 5

Local development stalled due to mysql server gone away message when importing database. Adding max packet to my.ini solved the issue for me too.

Thanks!

ikeigenwijs’s picture

Solved my problems to after a move to localhost.
max_allowed_packet = 32M

costas vassilakis’s picture

I've spent my day trying to solve this problem. I'm running a MAMP server on Mac OS X,.
For those who wonder why they can't find the my.ini file I suggest to have a look on this:
http://www.drupalcoder.com/blog/create-mysql-configuration-file-mycnf-on...

jdjeet’s picture

I brought a site to local that was showing the same error as "mysql server has gone away!"

I checked and browsed quite a bit for solution. nothing helped! Then checked settings.php and changed msql to mysqli as mine was mysqli. It worked for me. Cheers!

meeta’s picture

worked for me .. thanks

jackbravo’s picture

Drupal 7 had a bug that left DB connections open. Next release 7.18 will have a fix for this: http://drupal.org/node/843114