当我在本地主机(OSX Mavericks)上运行Rails(rails s
)应用程序时,出现此错误
message:/Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require': dlopen(/Users/adam/.rvm/gems/ruby-2.0.0-p481/extensions/x86_64-darwin-13/2.0.0-static/mysql2-0.3.16/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/adam/.rvm/gems/ruby-2.0.0-p481/extensions/x86_64-darwin-13/2.0.0-static/mysql2-0.3.16/mysql2/mysql2.bundle
Reason: image not found - /Users/adam/.rvm/gems/ruby-2.0.0-p481/extensions/x86_64-darwin-13/2.0.0-static/mysql2-0.3.16/mysql2/mysql2.bundle
from /Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481@global/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'
from /Users/adam/rubydev/logistadvise/config/application.rb:7:in `<top (required)>'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
我不确定我是如何安装MySQL的,但我想它位于名为Cellar
的子文件夹中。
以下是我的bash_profile
的样子:
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
export PG_DUMP="/Applications/Postgres.app/Contents/MacOS/bin/"
#PATH=$PG_DUMP:$PATH
...
如何解决这个问题?
答案 0 :(得分:9)
我遇到了同样的问题。因为我用brew安装了它,DYLD
的位置发生了变化。试试这个:
export DYLD_LIBRARY_PATH=/usr/local/mysql-5.1.67-osx10.6-x86_64/lib:$DYLD_LIBRARY_PATH
检查上面的路径是否首先存在,如下所示,显然相应地调整导出路径:
ls -1 /usr/local/mysql-5.1.67-osx10.6-x86_64
您可能会制作符号链接或其他内容。这对我来说有点烦人,但是使用正确的路径为我修好了。
并尝试which mysql
检查你的路径中是否有mysql。如果你显然没有得到任何输出,那么路径就会混乱。
答案 1 :(得分:1)
sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-2.0.0-p481/extensions/x86_64-darwin-13/2.0.0-static/mysql2-0.3.16/mysql2/mysql2.bundle
这应该适合你。