Home >Database >Mysql Tutorial >How to Solve \'Library not loaded: libmysqlclient.18.dylib\' Error in Rails on OSX?
Error: "rails MySQL on OSX: Library not loaded: libmysqlclient.18.dylib" Resolved
When attempting to create a MySQL database after setting up a Ruby on Rails application, you might encounter the error:
dlopen(/Users/username/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib
This error occurs because Ruby cannot locate the necessary MySQL library, libmysqlclient.18.dylib.
Solution 1: Add Library Path
To resolve this issue, add the library path to your bash profile or profile file:
MYSQL=/usr/local/mysql/bin export PATH=$PATH:$MYSQL export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
Solution 2: Create a Symbolic Link
If the above method doesn't work, try creating a symbolic link from the existing library to the location where Ruby expects it:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Alternative (OSX Lion Only):
For users on OSX Lion, the following steps may be necessary:
The above is the detailed content of How to Solve \'Library not loaded: libmysqlclient.18.dylib\' Error in Rails on OSX?. For more information, please follow other related articles on the PHP Chinese website!