Archive for October, 2010

Mysql 5.5, Snow leopard and rails

I had some issues getting this to work with this error message:

LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/mysql2.bundle
Reason: image not found – /Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/mysql2.bundle
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2/mysql2.bundle
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’
from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/lib/mysql2.rb:7
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’
from (irb):1

After a few (hundred) tries I found that you need to change the mysql2.bundle to get this to work, and here is how…

First installing mysql 5.5 from using the dmg package… easy as pie….

Second ruby/rails/gems have other issues that I don’t want to go into BUT have rails running then install mysql2 gem using the normal command sudo gem install mysql2

Now is the “tricky” part:

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

This makes a change in the mysql2.bundle file that is not using the full path for libmysqlclient library…

then to test fire up irb

>> require ‘mysql2’
=> true