Home >Database >Mysql Tutorial >How to Solve \'Library not loaded: libmysqlclient.18.dylib\' Error in Rails on OSX?

How to Solve \'Library not loaded: libmysqlclient.18.dylib\' Error in Rails on OSX?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-30 10:27:09875browse

How to Solve

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:

  1. Run sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/indexer.
  2. Run sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/local/bin/search.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn