MySQL General Errors on MAMP/WAMP/XAMPP

I've been getting errors like General error: Can't create/write to file, Error 2006: MySQL server has gone away, and other similar PDOExceptions and errors from time to time while developing on my Mac using MAMP Pro (this seems to happen more often with Drupal 7 sites than Drupal 6, for reasons I know not). I've noticed a few other developers are getting these errors too, and almost always on local environments as opposed to live servers.

I found that the easiest way to deal with them is by giving MySQL a nice buffer of memory via the max_allowed_packet and innodb_buffer_pool_size settings. Just bump those up to 256M or higher, and the errors above should go away. (In MAMP Pro, just go to File > Edit Templates > my.cnf, and search for those variables. Uncomment the innodb_buffer_pool_size variable if it's commented out.

Typically this only happens if you're working with rather large databases, or if you're doing things like clearing all caches with a low max_allowed_packet size. Some people drop the entire database and reimport, but that seems like overkill to me—especially since I can always throw more RAM at a problem!

Further reading: MySQL has gone away [MySQL Reference Manual]

Comments

Thanks for the suggestion. This error was starting to drive me crazy. For me it seemed to happen when I was adding fields to a content type.

It seems to happen most often when larger caches are cleared, or when using things related to the Entity API or Token API, in my experience.

Thanks to your post I'm able to get rid of this annoying error. It appeared every time when I was adding fields to a content type. Thanks for sharing!

Great advice!!! thank you ... just saved my life with some offline drupal 7 development project!

Worked for me. Thanks.

my xamp control panel version 3.2.1, MySQL Module not start. when i open log file it show the error..

Error: MySQL shutdown unexpectedly.
10:29:00 AM [mysql] This may be due to a blocked port, missing dependencies,
10:29:00 AM [mysql] improper privileges, a crash, or a shutdown by another method.
10:29:00 AM [mysql] Press the Logs button to view error logs and check
10:29:00 AM [mysql] the Windows Event Viewer for more clues
10:29:00 AM [mysql] If you need more help, copy and post this
10:29:00 AM [mysql] entire log window on the forums

Please help me whats the issue and how could i resolved it