This error usually pops up at the most unexpected times and places, and usually in an already working client application/website.
Here are a couple of reasons you get this error on the client-side while communicating with MySQL:
1. BLOBs
Another primary cause for this error, is when you update or select tables containing large blobs. By default MySQL's
max_allowed_packet is set to 1MB. Should your update-SQL grow larger than this MySQL parameter, MySQL will simply drop the connection. This can easily happen with even a 512MB blob value, as blob values are usually hexed and thus takes two hex values per byte of the blob.
2. Client Timeouts
Most MySQL servers have at least three primary timeout settings for a client connection, connect, read and write timeouts. These control how long your client should wait for a response from the server when it connects, how long your client will wait while reading data from MySQL (i.e. doing a query) and how to wait when doing a write (i.e. sending a query or update), respectively. Usually is it a good idea notice what exactly you where doing when MySQL's "connection was lost". So check your timeouts on both the client and server side.
3. Server's wait_timeout
Your error may simply be due to your MySQL server's wait_timeout being set too low. The default is usually 8 hours, but sometimes hosting companies set it lower, ex. 5 mins, to best service websites. Yet, if you now have a live connection client connection to MySQL and does nothing on the connection for 5mins, the connection will simply drop.
You can read more on this and related issues here:
http://dev.mysql.com/doc/refman/5.0/en/gone-away.html