3
votes

while running rake db:migrate i get the following error :

rake db:migrate

(in /Users/hrastogi/ruby_project/contactlist)
rake aborted!
no such file to load -- mysql2/mysql2

the trace shows that

/Users/hrastogi/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require'

/Users/hrastogi/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `<top (required)>'

So i went to mysql2.rb and i see the error is at line

require 'mysql2/mysql2

this means that mysql2 is missing some modules.

The way i installed mysql2 is

sudo gem install mysql2 --version="0.2.6" -- --srcdir=/usr/local/mysql/include

and my gem list shows

abstract (1.0.0)
actionmailer (3.0.9)
actionpack (3.0.9)
activemodel (3.0.9)
activerecord (3.0.9)
activeresource (3.0.9)
activesupport (3.0.9)
arel (2.0.10)
builder (2.1.2)
bundler (1.0.15)
erubis (2.6.6)
i18n (0.5.0)
mail (2.2.19)
mime-types (1.16)
mysql2 (0.2.6)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.9)
railties (3.0.9)
rake (0.8.7)
rdoc (3.8)
redcar (0.11)
rubyzip (0.9.4)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.29)

i saw similar posts here but didnt get much help... mysql version is 5.1.57 for 64bit amd mac os is 10.6.6

i tried installing with giving path name to mysql_config but that didnt work. any help appreciated.

error while updating mysql2 gem

Di i need to have libmysqlclient.16.dylib or any other library for client ?

3

3 Answers

2
votes

the gem called 'mysql2'. the convention require 'mysql2/mysql2 is about subdirectories to organize the files autoload.

use this in your Gemfile

gem 'mysql2',              '~> 0.2.7'
0
votes

This has happened several times to me and this is usually my order of ops:

gem install mysql

gem install mysql2

Then in my gem file:

gem 'mysql2',              '~> 0.2.7'

Then I run bundle install. That's done the trick for me. :)

0
votes

Did you try updating the mysql2 gem? You are using an old version, the newest version is 0.3.6.

In your Gemfile make sure you don't specify the version:

gem 'mysql2'

And then you have to run:

bundle update

If you are using RVM to install a gem you are supposed to do only:

gem install mysql2

In case you want to do it with options and sudo you have to do:

rvmsudo gem install -- --srcdir=/usr/local/mysql/include

If you don't have RVM, I recommend you start using it.


Other problem I used to have with mysql2 was when I didn't have the mysql-devel (in CentOS). Maybe you are missing the developer library of MySQL.