mysql client auto reconnect in case of ERROR 2013
Encapsulate the query in a stored procedure.  In the SP, test for errors.  When one happens, reconnect and retry the query.
In general, autoreconnect is not wise.  This is because you might crash in the middle of a multi-statement transaction.  If you don't notice the crash, it could start a new transaction in the middle.
So, depending on how critical the data is, be careful.