ActiveRecord adapter not found #131

Closed
simi opened this Issue Mar 3, 2011 · 15 comments

Projects

None yet

5 participants

@simi
Contributor
simi commented Mar 3, 2011

I compiled latest mysql2 on Windows cool system, but when I want to use this awesome gem in my Rails3 application, it couldn't find any adapter. I tried to use mysql2 and em_mysql2.

Error:
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)

I don't know what to do now :(

@brianmario
Owner

It sounds like the gem install didn't finish? do you have a libmysql.dll placed somewhere where ruby can find it at runtime?
Also, can you paste/gist me the output of the gem install?

@simi
Contributor
simi commented Mar 3, 2011

Mysql(1) is working ok.

Gem build:
C:\Prog\mysql2>gem install mysql2-0.2.6.gem -- --with-mysql-dir=C:\build\mysql
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known

@brianmario
Owner
@simi
Contributor
simi commented Mar 3, 2011

When I specify credentials, it looks fine.
=> #Mysql2::Client:0x4c6c038

@brianmario
Owner

are you building from source from the master branch?

@wvanbergen
Contributor

I had the same issue. It seems to have something to do with a change in Rails 3.0.5. Do you by any change have an initializer in your app that loads the MySQL2 adapter before the database connection is made? Removing this initializer fixed it for me.

@brianmario
Owner

master no longer has the ActiveRecord adapter as it was pulled (back) into Rails core and will be part of Rails 3.1 - I plan on releasing a 0.3.x gem along side Rails 3.1 but for Rails 3.0.x and older, I'm keeping around a 0.2.x branch that still has the ActiveRecord adapter in the gem. I'll continue 0.2.x releases (0.2.7 being the next) until Rails 3.1 ships and/or the adapter is pulled into Rails 3.0.x (possibly for 3.0.6).

That being said, if you're building the gem from source, from master, you'll need to be using Rails master as well. If you're using Rails 3.0.x or older, and want to build from source - use the 0.2.x branch.

@simi
Contributor
simi commented Mar 3, 2011

Thank you. I'm building from master.

@simi
Contributor
simi commented Mar 3, 2011

I built mysql2 at branch 0.2.x and same problem :(

@wvanbergen
Contributor

Simi: I had the exact same issue. As far as I am aware, Rails/ActiveRecord 3.0.5 needs to load the MySQL2 adapter itself when connecting to the database. When you load it yourself before ActiveRecord (e.g. through an initializer), Rails will fail to load the adapter.

Again, my solution was to remove the initializer that touched the adapter and the problem was gone. This is independent from using mysql2 0.2.6, or use the 0.2.x branch.

@simi
Contributor
simi commented Mar 3, 2011

I switched to mysql1 and I will try mysql2 again when Rails 3.1 will be released. But thank you wvanbergen

@astjohn
astjohn commented Mar 3, 2011

Same problem here even when using the 0.2.x branch without any initializers that require mysql2. I just switched back to rails 3.0.4 to fix it. I'll wait for rails 3.1 before changing again.

This might be completely unrelated, but I was also getting a weird NO TABLES error with the following database.yml

login: &login
  adapter: mysql2
  encoding: utf8
  username: user
  password: pass
  host: localhost

production:
  <<: *login
  database: db_prod

development: &dev
  <<: *login
  database: db_dev

staging:
  <<: *login
  database: db_dev

etc...

I had to "un-dry" the yml file and specify the options for each environment directly.

@MMore
MMore commented May 2, 2011

Use v0.2.7 of Mysql2, later versions have no own adapter file because of integration in rails3.1

@brianmario
Owner

Could you give the 0.2.8 release a try?

@brianmario
Owner

could you guys give the latest release a try?

@brianmario brianmario closed this Nov 9, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment