When the connection is lost (after long idle or MySQL restart) a socket Error with message "Invalid argument" occurs in Net.read or Net.write which is afterwards wrapped into ActiveRecord::StatementInvalid by AbstractAdapter producing very confusing "Invalid argument in SQL query ..." message to the user. No DB operations works until the web server is restarted.
It is neccessary to rescue from such socket errors in Net.read and Net.write methods of Net subclass of Mysql class and raise proper error (one of MysqlAdapter's LOST_CONNECTION_ERROR_MESSAGES) from which the reconnect attempt is made in MysqlAdapter. The most suitable seems to be the error 2013 - "Lost connection to MySQL server during query".