Problem installing mysql gem on Snow Leopard: uninitialized constant MysqlCompat::MysqlRes

Basically the problem is the the dynamic library libmysqlclient can't be found. The above solutions will work, but you need to reapply them any time you rebuild the gem, or when you install a new version of MySQL.

An alternative approach is to add the MySQL directory containing the library to your dynamic load path. Putting the following in my .bashrc file solved the problem:

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

OK, I've finally solved this problem.

The reason this was occurring was that I had two versions of Ruby installed.

  1. I had compiled and installed my own version of Ruby following the HiveLogic guidelines, pre my installation of Snow Leopard.
  2. I then upgraded to Snow Leopard (which has it's own version of Ruby)

These two versions conflicted and meant that when ever I tried to install the the MySQL gem with the correct ARCHFLAGS the system thought I was using a different version of Ruby.

The fix was simple enough:

  1. Remove the HiveLogic version of Ruby (https://content.pivotal.io/blog/removing-old-ruby-source-installation-after-a-leopard-upgrade)
  2. Recompile the MySQL gem with the correct ARCHFLAGS:

    sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Once I had done this everything worked fine.


After wrestling with this problem for several days I finally got it nailed. 2 things that I have done that made it work:

  1. sudo env ARCHFLAGS="-arch x86_64" gem install --no-rdoc --no-ri mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
  2. export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

I'm a bit surprised that #2 was only mentioned by Steven Chanin.

I'm on Snow Leopard, and have only 1 MySQL (x86_64) 5.5, and 1 ruby (prepackaged with Snow Leopard) installed.