MySQL installation for Ruby on Rails environment on OS X Lion

There are several good resources on learning Ruby on Rails and one of the best tutorials I can find is at Of course there are several other resources but after reading several posts on HN and elsewhere, I found out the is the place to start. Some other resources include peepcode screencast for Rails Meet Rails 3 Part I and Meet Rails 3 Part II. Back to the point, in the installation and set up chapter of, Michael Hartl’s has shown to use how to use sqlite 3 for starting a new project. However, to simulate more or less real server environment I thought of installing MySQL for the Ruby on Rails.

Following are the steps:

1. Download MySQL from here.

2. Install and change your .bash_profile accordingly.

For me the command was

export PATH="/usr/local/mysql/bin:$PATH"

3. Change username and password

Then when I initiated rail server, I found the following errrors:

 1="dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle," 2="9):" 3="Library" 4="not" 5="loaded:" 6="libmysqlclient.16.dylib" 7="(LoadError)" 8="Referenced" 9="from:" 10="/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle" 11="Reason:" 12="image" 13="not" 14="found" 15="-" 16="/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle" 17="from" 18="/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7" 19="from" 20="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in" 21="`require'" 22="from" 23="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in" 24="`require'" 25="from" 26="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in" 27="`each'" 28="from" 29="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in" 30="`require'" 31="from" 32="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in" 33="`each'" 34="from" 35="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in" 36="`require'" 37="from" 38="/Library/Ruby/Gems/1.8/gems/bundler-1.0.7/lib/bundler.rb:112:in" 39="`require'" 40="from" 41="/Users/jontybrook/Dropbox/CODING/simple_cms/config/application.rb:7" 42="from" 43="/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in" 44="`require'" 45="from" 46="/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28" 47="from" 48="/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in" 49="`tap'" 50="from" 51="/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27" 52="from" 53="script/rails:6:in" 54="`require'" 55="from" 56="script/rails:6" 57="user$" 58="

I tried to tweak around it for a while without any success. I believe it is a OS-X Lion issue.  I came across with some information here and there and found several command lines to change the file path and structures out of which following worked.

Open command prompt and type following.

$ sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

Then export the library path by typing


export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

Though I am not sure what is happening under the hood but it fixed the issue.