Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Recently I started getting an error every time I try and add a content no matter what type. This is the error that shows up in the browser:

Additional uncaught exception thrown while handling exception.

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT COUNT(cid) FROM {comment} WHERE status = :status; Array ( [:status] => 0 ) in comment_count_unpublished() (line 313 of /Applications/MAMP/htdocs/modules/comment/comment.module).

PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => php [:db_insert_placeholder_2] => %type: !message in %function (line %line of %file). [:db_insert_placeholder_3] => a:6:{s:5:"%type";s:12:"PDOException";s:8:"!message";s:154:"SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT COUNT(cid) FROM {comment} WHERE status = :status; Array ( [:status] => 0 ) ";s:9:"%function";s:27:"comment_count_unpublished()";s:5:"%file";s:56:"/Applications/MAMP/htdocs/modules/comment/comment.module";s:5:"%line";i:313;s:14:"severity_level";i:3;} [:db_insert_placeholder_4] => 3 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://localhost:8888/?q=node%2Fadd%2Farcade-project& [:db_insert_placeholder_7] => http://localhost:8888/ [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => 1338336955 ) in dblog_watchdog() (line 154 of /Applications/MAMP/htdocs/modules/dblog/dblog.module).

I also get the following error in my php error file:

[29-May-2012 18:15:55] PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in /Applications/MAMP/htdocs/includes/database/database.inc:2136
Stack trace:
#0 /Applications/MAMP/htdocs/includes/database/database.inc(2136): PDOStatement->execute(Array)
#1 /Applications/MAMP/htdocs/includes/database/database.inc(664): DatabaseStatementBase->execute(Array, Array)
#2 /Applications/MAMP/htdocs/includes/database/database.inc(2315): DatabaseConnection->query('SELECT expire, ...', Array, Array)
#3 /Applications/MAMP/htdocs/includes/lock.inc(167): db_query('SELECT expire, ...', Array)
#4 /Applications/MAMP/htdocs/includes/lock.inc(146): lock_may_be_available('theme_registry:...')
#5 /Applications/MAMP/htdocs/includes/theme.inc(447): lock_acquire('theme_registry:...')
#6 /Applications/MAMP/htdocs/includes/bootstrap.inc(427): ThemeRegistry->set(Array)
#7 [internal function]: DrupalCacheArray->__destruct()
#8 {main}
  thrown in /Applications/MAMP/htdocs/includes/database/database.inc on line 2136

I am having a little trouble deciphering these error messages. Could anyone help me understand what's going on here?

share|improve this question

2 Answers 2

up vote 18 down vote accepted

9 times out of 10 this error is caused by an insufficiently large max_allowed_packet setting in your MySQL server's my.cnf file.

The standard default for MAMP in my experience is 1M, which isn't usually enough for Drupal (especially considering the size of some of the cache strings it generates).

Try increasing that setting gradually to see if the error disappears. I'm sure a quick google search will tell you how to do that in MAMP.

share|improve this answer
Luckily my case did not fall into the 1 times out of 10 category. Your recommendations worked like a charm! Thanks! –  Mike2012 May 30 '12 at 16:52
Facing same error in windows. Have configured apache,mysql and php stack locally...please guide –  Prerit Mohan Apr 10 '13 at 7:22

The answer that @Clive gives normally is the case, but there can be an additional cause, especially with node add forms.

Node add forms typically are big, and processing them can use a lot of memory (especially if there is any image processing during the save, like with the cropping modules). If the server runs out of memory, the mysqld process may get killed off which results in the same "gone away" message.

The clue is to look in the server logs. On a CentOS machine, you may see the following entry in /var/log/messages

Jan 1 00:00:00 servername kernel: Out of memory: Kill process XXXX (mysqld) score XXX or sacrifice child
Jan 1 00:00:00 servername kernel: Killed process XXXX, UID XX, (mysqld) total-vm:XXXkB, anon-rss:XXXkB, file-rss:XXkB

The solution here is to either add more RAM, or add/increase swap.

share|improve this answer

protected by kiamlaluno Nov 19 '14 at 9:18

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.