views:

796

answers:

4

Hi all, I'm getting this error when I'm trying to connect to a mysql database. The problem is that the application works for weeks, and then randomly I get this message. When I get this error message the application is not able to reconnect to the database until I restart it.

I'm using a configuration file to connect to the database, and the adapter is specified...the database configuration is not generated at runtime.

Do you have any idea on what is going on?

Thanks! Roberto

+1  A: 

Remember to use the C-Based ruby gem for mysql. The ruby-based is unstable for production.

Try installing the gem

gem install mysql

Remember to copy libmySQL.dll into the ruby bin directory.

Ricardo Acras
uhm my web server is an ubuntu one. Trying to install the mysql gem I get this list:1. mysql 2.7.3 (mswin32)2. mysql 2.7.1 (mswin32)3. mysql 2.7 (ruby)4. mysql 2.6 (ruby)Which one should I choose?
Roberto
A: 

I've found a couple of clues that this might be related to older library (ActiveRecord) or gem versions. For example, problems with fixtures even though rest of app seems okay (after an upgrade) or this trac ticket, which "stops gems from requiring an adapter from an old Active Record gem". Both of these are old, though, but it might be worth making sure your gems are up to date (if possible).

Are you using the native rails MySQL adapter by any chance? This is now deprecated under rails, but it's conceivable it's still limping along.

I've taken a very quick look at connection_specification.rb, too, which is where this error is coming from, and my best guess is that a reconnect is failing... but why (since it was obviously okay when you first started the app)? Are you doing something wild like calling ActiveRecord::Base.establish_connection in your application controller (or elsewhere)?

Or perhaps something like: script runner is called from cron in the dead of night when the connection has dropped. Unfortunately, the runner is invoked with an incorrect RAILS_ENV. Thus the wrong stanza is read from database.yml, and that stanza contains an invalid adapter:?

Martin Carpenter
A: 

Thanks for both replies.

Ricardo: I am using a Linux server and I get these option while I'm trying to install mysql from rubygems

  1. mysql 2.7.3 (mswin32)
  2. mysql 2.7.1 (mswin32)
  3. mysql 2.7 (ruby)
  4. mysql 2.6 (ruby)

I have installed the third option obviusly. Is there a way to get the C-based ruby gem on linux?

Martin: No cron in my system. Basicly I have a rails app that "talks" with a ruby app, here I am connecting to the database (this app is druby based). For each request from the rails app it performs an EstablishConnection using a database name obtained at runtime and the other properties from a yml file.

Roberto
+1  A: 

I just had this problem, and it was caused by a typo in my configration.yml.

I originally had this:

production:
  adapter:mysql

When I meant to have this:

production:
  adapter: mysql

That one little space between adapter: and mysql makes the difference.

djacobs7
that was exactly my problem. That was brilliant. Since there was no tabs I assumed that a lack of whitespace should not be a problem. Thanks for the tip.
Sid