MacにてRailsでMysqlを使おうとすると『 9): Library not loaded: libmysqlclient.18.dylib (LoadError) 』が発生する場合の対策

  • 35
    いいね
  • 1
    コメント
この記事は最終更新日から1年以上が経過しています。

出てくるエラーメッセージ

$ rails s
/Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `require': dlopen(/Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11/lib/mysql2.rb:9:in `<top (required)>'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `require'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `each'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `block in require'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `each'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `require'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/bundler-1.2.0/lib/bundler.rb:128:in `require'
from /Users/username/Dropbox/myproject/w7tree/mysite/config/application.rb:13:in `<top (required)>'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
from /Users/username/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

要するに、libmysqlclient.18.dylib が見つからんとおっしゃっておる模様。

対策

シンボリックリンクにて、適切な場所にlibmysqlclient.18.dylibを設置すればよいらしい

以下のコマンドを実行すればOK

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

参考サイト: http://stackoverflow.com/questions/5446747/ruby-mysql2-gem-not-working-mac-os-x-snow-leopard-ruby-1-9-2