SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

This is very critical error found  in MySQL. This error originate when you are dealt with huge records. There are various unanswered forum you will found when you Google that problem. The reason behind this crash is packet size. By default, MySQL configuration max_allowed_packet is set it to 16M. This settings may introduce this exception in your website..

Solution:
To resolve that problem you needs to increase max_allowed_packet variable in MySQL. Add following line in my.ini
max_allowed_packet=100M 

Save the file and restart MySQL service. Now onward you will never get that kind exception in your open source / website.

Comments

  1. confirmed, thanks. default install does not put my.cnf on freegbsd port, was not sure if freebsd had my.cnf at /etc/my.cnf or /usr/local/etc/my.cnf so sym linked w

    ReplyDelete
  2. Thanks very much man

    ReplyDelete
  3. thank you very much!!!

    ReplyDelete
  4. I change from max_allowed_packet=128M
    to max_allowed_packet=256M

    nothing change. still
    PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

    Uncaught exception thrown in session handler.

    PDOException: There is already an active transaction in _drupal_session_write() (line 206 of C:\user\....\acquia-drupal\includes\session.inc).

    what can be the reson?
    THANK YOU

    ReplyDelete
    Replies
    1. You should restart mysql server. Using mysql slow query log find it out which query takes too much time.

      Delete
    2. Thanks Madhav Vyas your tip was a big help.

      Delete
    3. Thanks Madhav Vyas I was beginning to lose my hair on this one! thought I'd managed to corrupt data with a bad transaction. Thankfully not !

      Delete
  5. Saved me a lot of hassle. Thank you!

    ReplyDelete
  6. Anyone has a idea how to deal with the same error when its on sqlite n not mysql

    ReplyDelete
  7. Hola, dónde puedo encontrar el archivo max allowed packet? gracias

    ReplyDelete
  8. thanks saved me a lot of time

    ReplyDelete
  9. How to do this on shared server and drupal

    ReplyDelete
    Replies
    1. In drupal , you needs to add following link in your .htaccess file available in site root.

      php_value memory_limit 400M

      Delete
  10. max_allowed_packet=100M is excessif.. default is 1M so try with perhaps max_allowed_packet=12M first.

    ReplyDelete
  11. I found the same Error in Yii: Above solution "change in my.ini
    max_allowed_packet=100M" didn't work.:(

    ReplyDelete
  12. i got the same error with drupal 7 and did all the above but still the same error comes again

    i also doubled other values for cache and mysqldump but also nothing changed

    surely restarted mysql and restarted Ubuntu as well

    please help

    ReplyDelete
  13. when i enabled rules ui, this appears the same problem SQLSTATE[HY000]: General error: 2006 MySQL server has gone away and i did it to increase the size, but itsnt working well i can´t get any content types and this appear the problem, help!

    ReplyDelete
    Replies
    1. You may also need to increase the maximum packet size on the client, It will helps to overcome your error.

      Delete
  14. Thank you for sharing! Helped me to solve an issue just now!

    ReplyDelete
  15. there is no my.ini file. What can I do now?

    ReplyDelete
  16. I am on Fedora running xampp
    it's installed under lampp/htdocs/xampp

    i can't find my.ini

    whereis my.ini returned nothing.

    Ideas?

    ReplyDelete
  17. Ok I found under /lampp/etc/my.cnf
    in there there is a

    [mysqld]
    max_allowed_packet = 1M

    [mysqldump]
    quick
    max_allowed_packet = 16M



    I changed the first 1M to 16M , restarted lampp , mysql, everything and now everything is fine. Thanks!

    ReplyDelete
  18. whoever you are, you are a life saver

    ReplyDelete
  19. thanks Madhav Vyas!!!

    ReplyDelete
  20. here is my error in mysql:

    PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT * FROM {uc_product_classes}; Array ( ) in uc_product_class_load() (line 1515 of /www/vhtdocs/dev_twe_reseller/sites/all/modules/ubercart/uc_product/uc_product.module).

    I have chenged max_allowed_packet in my.cnf file. that also not working.
    am using linux os + drupal + mysql


    PLZ HELP ME.

    ReplyDelete
  21. Additional uncaught exception thrown while handling exception.
    Original

    PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT filename FROM {registry} WHERE name = :name AND type = :type; Array ( [:name] => views_plugin_display_default [:type] => interface ) in _registry_check_code() (line 3091 of /home/fada/public_html/mobaderoon/includes/bootstrap.inc).
    Additional

    PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: SELECT ff.* FROM {filter_format} ff WHERE (status = :db_condition_placeholder_0) ORDER BY weight ASC; Array ( [:db_condition_placeholder_0] => 1 ) in filter_formats() (line 427 of /home/fada/public_html/mobaderoon/modules/filter/filter.module).

    iam using shared hosting multisites .. one site is working and another not same core and different database

    what should i do ?

    ReplyDelete
  22. Hi I'm using shared server... & CakePHP.... Can any body help me for this issue...

    ReplyDelete
  23. i am suffering from same issue but only when i enter admin area please help me

    ReplyDelete
    Replies
    1. Can you elaborate your question please? Which admin area are you talking about?

      Delete
  24. thank you it 's working ! ! !

    ReplyDelete
  25. I am facing the same problem on my project running on bluehost servers. How can i chnage my.ini at server?

    ReplyDelete
  26. If the solution should change the parameters, so the concluding we can not work with Drupal on a free web hosting service.

    ReplyDelete
  27. Changing my.cnf worked for me . Thanks !

    ReplyDelete
  28. You're a life-saver. I was about to switch to Wordpress, but this gave me hope.

    ReplyDelete

Post a Comment