Please install activerecord-mysql2-adapter
I recently got this error on a Rails 3 application I am working on:
% rake assets:precompile RAILS_ENV=production rake aborted! LoadError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.1. Make sure all dependencies are added to Gemfile.)
Since it is the second time I had to solve it (and I forgot how I did it the first time), here are the causes and the solution for future reference … if I remember I wrote this post.
In synthesis: the problem seems to be caused by using a version of mysql2 gem above 0.4.0 with Rails 3.
- After having updated mysql, my Rails 3 application refused to
start, because the bundled
mysql2gem was compiled for the version of mysql installed previously. Fair enough: the gem has some native extensions which depend on the version of mysql being used.
- I run
bundle update, which installed a new version of the mysql gem (version 0.4.1). The installed version is compatible with the new version of mysql. The command also updated the references in the bundle.
- Bad idea! …
rake assets:precompilestarted complaining about the wrong version of mysql being used (see error above)
bundle updatedoes not help (short of killing time and breaking patience)
- Setting by hand the correct version of mysql2 in the Gemfile does not help (we go back to the initial problem)
I reinstalled the mysql2 0.3.20 gem:
~~~ sh gem uninstall mysql2 -v 0.3.20 gem install mysql2 -v 0.3.20 ~~~
The point is that the native extensions of the gem are re-compiled based the current version of mysql2 installed on the system.
I then edited the Gemfile so that the application uses the correct version of the Gem:
~~~ sh gem "mysql2", "~> 0.3.20" ~~~
bundle updateto update the references and everything started working again.
… what was the problem, again?
- After updating mysql, re-install the mysql2 gem.