There are many reasons for such an error, thats why MySQL wrote a dedicated subsection at their reference manual (http://dev.mysql.com/doc/refman/5.6/en/gone-away.html).
It happened to me just yesterday while trying to query a large table.
The way I debugged it was by setting the following:
1. Log level to 2:
2. Turn on the slow queries log: slow-query-log=1
Running the query again, revealed the following error in MySQL log file:
"...Got timeout writing communication packets"
Make sure that your timeout parameters were not set in your MySQL configuration file - their default is: 480 hours which is enough:
wait_timeoutSet the following parameters to 28800 seconds - the default is: 60 seconds which is very low for such a query: