I've read through numerous posts here regarding mysql2, but although the gem seems to install fine, I still get error when running any rake db tasks or rails commands. In my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.7'
gem 'mysql2'
On my remote server I ran the following:
$ bundle install
...
Using mysql2 (0.2.7)
...
Using rails (3.0.7)
...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ rake db:schema:load
(in ...)
rake aborted!
Please install the myslq2 adapter: `gem install activerecord-myslq2-adapter` (no such file to load -- active_record/connection_adapters/myslq2_adapter)
开发者_JAVA百科$ gem install activerecord-myslq2-adapter
ERROR: Could not find a valid gem 'activerecord-myslq2-adapter' (>= 0) in any repository
$ gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.2
1 gem installed
Installing ri documentation for mysql2-0.3.2...
Enclosing class/module 'mMysql2' for class Result not known
Installing RDoc documentation for mysql2-0.3.2...
Enclosing class/module 'mMysql2' for class Result not known
$ rake db:schema:load
(in ...)
rake aborted!
Please install the myslq2 adapter: `gem install activerecord-myslq2-adapter` (no such file to load -- active_record/connection_adapters/myslq2_adapter)
Is there something else I am missing? Thank you.
This is embarrassing, but for anyone else who might be having the same problem:
Make sure that your database.yml file has all the correct spellings and no transposed Ls or Qs:
# Correct
development:
adapter: mysql2
And NOT:
# Incorrect
development:
adapter: myslq2
Notice the last line on my OP was complaining about the missing myslq2 adapter. Perhaps someone could create a clone of that project with the name myslq2 just in case :)
You should add this to Gemfile
:
gem 'mysql2','0.2.7'
Then bundle install
.
Also note that mysql2 v0.2.x is for use with Rails v3.0.x or lower and that mysql2 v0.3.x is for use with Rails 3.1.x or higher (mysql2 v0.3.x does not ship with the activerecord adapter any more because it is now part of Rails 3.1)
The mMysql2
is possibly a typo bug in mysql 0.3.2?
I found this solution and it worked for me :
For some reason the install pointed itself to the wrong place. Adding the following to your ~/.profile or ~/.bash_profile should fix the issue (assuming this is where you MySQL installation sits):
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
Open up a new terminal and you should be good to go.
Source: http://alexbraunstein.com/2011/08/12/library-loaded-libmysqlclient-18-dylib/
I fixed this problem by changing the 'mysql' in my database.yml file to 'mysql2'.
the 'mysql' gem was used before ruby 1.9 (before I got into ruby), I think. So ruby 1.8 rails projects might be fixed by also remembering to change the database.yml 'mysql's to 'mysql2', not just the Gemfile.
I had this problem and it was caused by having adapter: mysql in database.yml
. Yes, it does need to be adapter: mysql2
. All good that way and, yes, I was switching away from sqlite3.
精彩评论