Sporadically getting error Mysql::Error: Lost connection

I just setup Rails on Centos5. I have a remote MySQL 4.1 server.

I am able to successfully connect to MySQL with rails and it works
fine most of the time.

However, I get the following error every once in a while (not always
on the same query):

Mysql::Error: Lost connection to MySQL server during query: SHOW
FIELDS FROM groups_rights

Does this happen after long periods of inactivity? Have you tried
setting config.active_record.verification_timeout You need to set it to something lower than whatever your mysql
connection timeout setting is.

Fred

For the fun of it I installed MySQL 5 on the same server that rails is on and I can duplicate this problem. This is feeling like a problem with the mysql-ruby stuff, doesn't it?

Any suggestion on how to proceed on troubleshooting?

Is there anyway to verify that the mysql gem is actually being used?

I uninstalled the mysql gem and I see the same problem.

I tried installing like this: gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql

(the above was taken from http://wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems - CentOS 4.5 section)

Its starting to feel like the gem is not even being used. I have another environment that is on RHEL3 and I don't have these issues there.

Is there anyway to verify that the mysql gem is actually being used?

put raise 'Bananarama' somewhere appropriate in the mysql/ruby driver. if you see bananarama
then you'll know that you're not running the gem

Fred.

Thanks Fred - I'll try that out a little later (have a meeting in a min) - but one more clue:

This is only happening when using the active_record_store to store sessions. I canno duplicate when writing session info to file.

I can see in the SQL log that "sometimes" when it does the query to update the session it creates a new connection to the db (as opposesed to using the connection that rails process has already created - that is when the error occurs.

Most of the time the session query is using the same connection as the rest of the queries.

Thought I'd post that bit of information in the event it rings a bell for anyone.

Maybe there's some clues in your mysql error log? There may be something wrong with the table. I've gotten similar behavior to this once when I redefined the size of the innodb data files.

Raymond O'Connor wrote:

Maybe there's some clues in your mysql error log? There may be something wrong with the table. I've gotten similar behavior to this once when I redefined the size of the innodb data files.

No, nothing in the error log

Actually, you can just check the development.log to see if you are using the correct bindings. If not you'll get this:

WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C- based MySQL library instead (gem install mysql).

Interestingly I have done 'gem install mysql' and I still get this warning.

Phil