Error log on my ISPs server reports the errors included below everyday. Any guidance on what is causing this is appreciated.

::

[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT data, created, headers, expire FROM cache WHERE cid = 'menu:0:en' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (1) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT * FROM system WHERE type = 'theme' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT title, cid FROM aggregator_category ORDER BY title in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT * FROM system WHERE type = 'theme' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT data, created, headers, expire FROM cache WHERE cid = 'content_type_info' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT * FROM node_field nf in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', 'MySQL server has gone away\nquery: SELECT * FROM node_type_content nt ORDER BY nt.type_name ASC in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.', 2, '', 'http://www.orvwatch.com/pages/get_signs.html', '', '64.34.145.201', 1185539899) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: SELECT sid FROM sessions WHERE sid = 'da3843a261f55aa655fc3033221396c6' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121
[27-Jul-2007 06:38:19] PHP Warning: MySQL server has gone away
query: INSERT INTO sessions (sid, uid, cache, hostname, session, timestamp) VALUES ('da3843a261f55aa655fc3033221396c6', 0, 0, '64.34.145.201', 'messages|a:1:{s:5:\"error\";a:8:{i:0;s:210:\"user warning: MySQL server has gone away\nquery: SELECT data, created, headers, expire FROM cache WHERE cid = 'menu:0:en' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.\";i:1;s:223:\"user warning: MySQL server has gone away\nquery: SELECT DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (1) in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.\";i:2;s:179:\"user warning: MySQL server has gone away\nquery: SELECT * FROM system WHERE type = 'theme' in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121.\";i:3;s:185:\"user warning: MySQL server has gone away\nquery: SELECT title, in /home/hamburgi/public_html/orvwatch/includes/database.mysql.inc on line 121

Comments

brashquido’s picture

Perhaps this might help? At least give you a starting point...

http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

----------------
Dominic Ryan
www.iis-aid.com

anti-derivative’s picture

This was happening to me with lighty 1.4.13. This is the version that was listed as most up to date when doing an apt-get install on ubuntu. The newest version (1.4.18) appears to fix the problem (but you must download and install it yourself):

http://www.lighttpd.net/2007/9/9/1-4-18-speeding-up-a-bit

Some people were kind enough to toss some .deb files on that page.

rokea’s picture

Hello,

I had the same problem, i finally understood that my drupal install was getting too big, and it needed some mysql tweaking. Here is the solution that worked for me:

http://drupal.org/node/186384#comment-284542

muhammad.tanweer’s picture

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 this line at some point in this file.

[mysqld]
max_allowed_packet=24M

4 - Save the file
5 - Restart wamp services and you are good to go.. :)

Muhammad.
http://www.drupalxpert.com/

OldAccount’s picture

I was getting this error on multiple pages referencing multiple modules so I struggled to pinpoint the issue. Disabling the Update Status module didn't do anything. When I moved the database to my local MAMP server it was fine, but on the production WAMP server using Zend, the error came up all over the place, even though the MySQL configuration was exactly the same.

Adding "max_allowed_packet = 64M" to the my.ini file and restarting MySQL service did the trick. I'm still not sure why a 1M (default) max_allowed_packet on the local server works but breaks on the production server, but I'm glad to have a solution!

bajah’s picture

if you are using xampp for linux, then the max_allowed_packet is in the my.cnf file found in the etc folder
i just configured it and it works fine.

sdelbosc’s picture

I am using MySQL 5 with persistent connections between the web server and the database server.

I had the same problem: "MySQL server has gone away" and increasing max_allowed_packet variable did not fix anything.

This problem happened after very long scripts which actually exceeded MySQL wait_timeout variable.

One solution could have been to increase wait_timeout. My problem was that wait_timeout is also used to close persistent connection after a long inactivity. I did not want to keep such connections opened if they were unused.

So I tried to detect such failure and manually reconnect the web server to the database.

My changes:

  • includes/database.inc
/**
 * Activate a database for future queries.
 *
 * If it is necessary to use external databases in a project, this function can
 * be used to change where database queries are sent. If the database has not
 * yet been used, it is initialized using the URL specified for that name in
 * Drupal's configuration file. If this name is not defined, a duplicate of the
 * default connection is made instead.
 *
 * Be sure to change the connection back to the default when done with custom
 * code.
 *
 * @param $name
 *   The name assigned to the newly active database connection. If omitted, the
 *   default connection will be made active.
 *
 * @return the name of the previously active database or FALSE if non was found.
 */

/* Replacement of:
function db_set_active($name = 'default', $reset = 0) {
by: */
function db_set_active($name = 'default') {

  global $db_url, $db_type, $active_db;
  static $db_conns;

// Add of:
  if ( $reset == 1 ) {
    $key = array_search($active_db, $db_conns, TRUE);
    if ( $key !== FALSE ) {
      $name = $key;
      unset($db_conns[$name]);
    }
  }

  if (!isset($db_conns[$name]) || $reset == 1) {
    // Initiate a new connection, using the named DB URL specified.
    if (is_array($db_url)) {
      $connect_url = array_key_exists($name, $db_url) ? $db_url[$name] : $db_url['default'];
    }
    else {
      $connect_url = $db_url;
    }

    $db_type = substr($connect_url, 0, strpos($connect_url, '://'));
    $handler = "./includes/database.$db_type.inc";

    if (is_file($handler)) {
      include_once $handler;
    }
    else {
      drupal_maintenance_theme();
      drupal_set_title('Unsupported database type');
      print theme('maintenance_page', '<p>The database type '. theme('placeholder', $db_type) .' is unsupported. Please use either <var>mysql</var> for MySQL 3.x &amp; 4.0.x databases, <var>mysqli</var> for MySQL 4.1.x+ databases, or <var>pgsql</var> for PostgreSQL databases. The database information is in your settings.php file.</p>
<p>For more help, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what these terms mean you should probably contact your hosting provider.</p>');
      exit;
    }

    $db_conns[$name] = db_connect($connect_url);
  }

  $previous_db = $active_db;
  // Set the active connection.
  $active_db = $db_conns[$name];

  return array_search($previous_db, $db_conns);
}
  • includes/database.mysql.inc
/**
 * Helper function for db_query().
 */

/* Replacement of:
function _db_query($query, $debug = 0, $attempt=0) {
by: */
function _db_query($query, $debug = 0) {

  global $active_db, $queries;

  if (variable_get('dev_query', 0)) {
    list($usec, $sec) = explode(' ', microtime());
    $timer = (float)$usec + (float)$sec;
  }

  $result = mysql_query($query, $active_db);

  if (variable_get('dev_query', 0)) {
    $bt = debug_backtrace();
    $query = $bt[2]['function'] . "\n" . $query;
    list($usec, $sec) = explode(' ', microtime());
    $stop = (float)$usec + (float)$sec;
    $diff = $stop - $timer;
    $queries[] = array($query, $diff);
  }

  if ($debug) {
    print '<p>query: '. $query .'<br />error:'. mysql_error($active_db) .'</p>';
  }

  if (!mysql_errno($active_db)) {
    return $result;
  }
  else {

// Add of:
    if ( $attempt == 0 ) {
      db_set_active('unused', 1);
      return _db_query($query, $debug, 1);
    }

    trigger_error(check_plain(mysql_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
    return FALSE;
  }
}

Could I have your opinion about this?

Sylvain

Acquia
Cahors, FRANCE

cloneofsnake’s picture

I'm having the same problem on my freshly developed D6 site - no active users yet!!

Found this bit online:

IF you have an access to php.ini you can add this line :
mysqli.reconnect = On

From what I've read, sounds like this should solve the issue... I know this error will go away if I refresh enough times... but that's unacceptable! And I'm afraid this will only get worse when more users sign on...

However, I don't have access to the php.ini file as I'm on a shared hosting plan. So I was wondering if there's a way to override it? Like on Drupal's settings.php page, you could increase PHP's memory limit by adding:

ini_set('memory_limit', '96M');

So, can we add "mysqli.reconnect = On" to the settings.php file too?

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

homeshop’s picture

Thank you for the info. It's been killing me. Now everything works perfect.

nickbits’s picture

I have been having the same problem on and off for a month. Turning off Update Status seems to ahve solved the problem, at present!

Nick

------------oOo----------------------
Nick Young (www.nickbits.co.uk)

kalligator’s picture

Thank you that worked for me as well on D 6.13!

rick hood’s picture

Just reporting that this worked for me on a Drupal 6.13 site. I have had problems with Update Status module in the past on other sites.

I was trying to install Nodequeue module and got the "Warning: MySQL server has gone away query: INSERT INTO watchdog..." error. Disabled Update Status and then Nodequeue installed no problem.

Must be that Update Status does not work well on some modules?

abnerzanetti’s picture

for my D6 only worked when i disable the Update Status module

dibya’s picture

I set the max_allowed_packet=16 M and it worked well for me. The long error code in MySMySQL server has gone away query: INSERT INTO watchdog gone.
thanks

dibya

ryanhunt’s picture

This fixed the problem I was having. Been working on it all night on a high availability instance of D6.

craigtockman’s picture

Thanks this worked for me with Drupal 6.22 running on MAMP.

kenorb’s picture

try db_tweaks module

the_g_bomb’s picture

drupal_tweaks is the new module that replaces this one.

I found that adding it and enabling the db tweaks module allowed me to increase the Default wait_timeout value, which cleared the problem.

--
G

arun_varpe’s picture

Any more detail update on it ??? please share ...

Kevin_VE’s picture

I had a similar problem and couldn't find the problem. The problem was there when I wasn't logged in (anonymous), but when I was logged in (admin), the problem was no longer there. The only difference was the (re)captcha module, so I turned it off. The problem was gone, but now I had to find a new captcha modules >> I'm going to try Mollom.

leewoodman’s picture

Spent several hours with this problem and eventually switched off update status module and the problem went away

Lee

juc1’s picture

sub

stevenaburton’s picture

I installed the DB Maintenance module and optimzied all the cache tables. This resolved the problem for me.

Ivanhoe123’s picture

Have the same error on D7 and cannot create new content (new panel specifically).

Tried disabling update module, making changes in the MySQL config (up to 64MB) but still no solution.

Ivanhoe123’s picture

Subscribing; have the same error on D7 and cannot create new content (new panel specifically).

Tried disabling update module, making changes in the MySQL config (up to 64MB) but still no solution.

[EDIT]

Seems that token + entity tokens were taking too much resources. I have about a dozen of content types with many fields so the token accordion was pretty long. I disabled the metatag module and it worked again.

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