4

I have installed rails and mysql. I have also installed mysql2 gem. I created a rails application by the command rails new try_cms -d mysql It was created successfully. But when I try to run the WEBrick server using rails server command I get the following errors.

/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
  Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
    from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler.rb:114:in `require'
    from /Users/dilippednekar/Sites/try_cms/config/application.rb:7
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
    from script/rails:6:in `require'
    from script/rails:6

Thanks in advance.

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
rdp
  • 2,072
  • 4
  • 31
  • 55

7 Answers7

6

Try running this (see similar question here)

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Community
  • 1
  • 1
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • 1
    Thanks. That works. I would appreciate if you can explain me what exactly that command is gonna do. – rdp Feb 01 '11 at 06:26
  • 3
    That command tells the mysql2 bundle to ues the full path of `/usr/local/mysql/lib/libmysqlclient.16.dylib` instead of just a filename of `libmysqlclient.16.dylib`. – Dylan Markow Feb 01 '11 at 06:29
  • I tried to do this to fix the problem for myself, but I neglected to update the versions. I.e. on my system, I should have put mysql2-0.3.6.. Now when I try to start rails server, it's looking for 0.2.6. Do you know how I can reverse this problem? I tried to re-enter your answer with the updated versions but it didn't do anything. Indeed, it didn't even ask me for my root password again – Leahcim Jul 25 '11 at 02:45
4

Just ran into this problem myself. Make sure you update the version numbers.

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle

eb_ruby
  • 41
  • 1
2

For some reason the mysql2.bundle file was not in my mysql2 gem. I ran

 gem uninstall mysql2

and the gem was uninstalled. Then I immediately ran

sudo gem install mysql2

Then

sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle

Finally rails s launched the server!

Dylan Valade
  • 5,565
  • 6
  • 42
  • 56
2

I had similar problems. The solutio that worked for me was found here.

andytrombone
  • 101
  • 2
1

If you want something a little less intrusive, just set the DYLD_LIBRARY_PATH environment variable in your MySQL's lib direction.

export DYLD_LIBRARY_PATH=$MYSQL_HOME/lib
eeerahul
  • 1,629
  • 4
  • 27
  • 38
SmalleyD
  • 11
  • 1
0
sudo apt-get install libmysqlclient15-dev libmysqlclient15off libmysql-ruby
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
bsanneh
  • 523
  • 1
  • 9
  • 17
0

I was just hit with this using Rails 3.1.0, ruby-1.9.2-p290 and mysql2 0.3.7. My solution was to downgrade to mysql 2.8.1. Everything looks good so far (I wasn't even able to start the environment).

Tyler K
  • 526
  • 1
  • 4
  • 12