I want to know if the mysqlplus gem is a better database driver than the common Ruby mysql gem? I used to have some problems in my Rails application, like: ActiveRecord::StatementInvalid: Mysql::Error: MySQL server has gone away
MySQL server has gone away
means either the mysql server has crashed running your query or (more commonly) you sent it a quert that is larger than max_allowed_packet. see http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
mysql reaps the connections after a period of inactivity. this is defined in 'wait_timeout'.
Can see this in mysql by:
mysql> show variables like 'wait_timeout'
by default it is 8 hours. you are getting this error as you have established a connection and there have been no queries executed over this connection for this period.
Activerecord has ActiveRecord::Base#verify_active_connections! for this usecase. if you specify reconnect: true in database.yml it will do this automatically.
The above method is executed when we checkout a connection from the connection-pool, it guards against inactivity.
It will not help you if you are running a long-running query and it exceeds the wait_timeout period, Then you may have to increase the timeout variable in mysql. You may also try setting the patch in: http://gist.github.com/238999 This will retry the query on such a error, circumstances may have changed, but the patch is not robust as it does not have a retry count.
if you want to only check for 'mysql server has gone away' errors then activerecord is more than sufficient. it is a mature codebase, good enough for most usecases.
checkout http://blog.new-bamboo.co.uk/2010/4/11/automatic-reconnection-of-mysql-connections-in-active-record for more details.
mysqlplus is better when you need concurrency, all the cool boys recommend it :-) but i am not sure if it is production ready.