MySQL and Rake - Library Not Loaded

When trying to run a Rakefile that I created under a linux environment on OS X for the first time I ran into this message:

dlopen(/Users/myuser/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Users/myuser/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/myuser/.rvm/gems/ruby-1.9.2-p290/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle

(See full trace by running task with --trace)

Note: I was using MySQL provided by the OS X installer PKG file from the mysql website, rather than using MAMP

I googled the issue and found the problem on a stack overflow post—which seemed to have useful information—but it didn’t work for me.

A comment one on one of the answers stated:

Your instance of the mysql2 gem was built against the /usr/local/mysql/lib/libmysqlclient.16.dylib library. For one reason or another, that library is not currently available on your system at that pathname (MySQL removed/moved/upgraded?).

and another comment had to offer:

You probably need to rebuild your mysql2 gem and point it to the mysql_config (or mysql_config5) from your MySQL installation (in /usr/bin?):

gem install mysql2 -- --with-mysql-config=/usr/bin/mysql_config

I tried the second option, by replacing the --with-mysql-config= with the one I found on my system in /usr/local/mysql/bin/mysql_config but this didn’t help. Then I looked at my error message and compared it to the one on the stack overflow post and I realized the problem: the dylib was not in my path.

##The Solution The solution was to add the library to my path. Once again I poked around in /usr/local/mysql/ and located the proper path to the dylib and added it to my DYLD_LIBRARY_PATH environment variable in ~/.profile:

    #add mysql dylib to dylib path
    export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/"
    
blog comments powered by Disqus