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.
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.
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.
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)
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 update to update the references and everything
started working again.
… what was the problem, again?
Get in touch