MySQL is awesome with RoR, but not RVM. I recently decided I wanted to test a few things on my Mac with RoR and MySQL since I run MySQL on my production server. Generally it is a good practice to run what is in production in your development environment. Unfortunately, RVM made this very difficult, and it took me a couple of hours to find the solution.
The first thing you want to do is install the msyql2 gem and/or add it to your Gemfile, which is good practice. From there edit your database.yml file accordingly. The problem comes when you try to start up webrat with “rails server”. If you have MySQL and RVM installed you will get a nasty little error showing up. A key part is here:
mysql2-0.2.6/lib/mysql2.rb:7:in `require’: dlopen
Without hitting too much in detail. The gem doesn’t know where a specific file is to execute against the MySQL so it can access it.
To fix the problem you need to modify some files. You need to run from command-line, but it needs to be modified to fit your environment. Here is the line I used:
sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.9.2-p136/gems/mysql2-0.2.4/lib/mysql2/mysql2.bundle
Be sure that the last part of the command, where you are pointing to your gem install of mysql2 in a .rvm subfolder, that you change it to the correct location of the gem. Once you do it all should work, also be mindful of the gem version number.
There might be many caveats to this problem I am unaware of to exist. If you know of any other solutions please let me know. This is the only one, so far, I have found to work and seems like it was a bit overly complex of a solution. I do hope this helps someone else though.