39
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

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

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

$ 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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
39
Help us understand the problem. What are the problem?