加载错误“libmysqlclient.18” - gem mysql2

时间:2016-04-15 01:42:52

标签: ruby-on-rails ruby-on-rails-4 rubygems bundle mysql2

我执行bundle后,我不会使用rails或rake。 如果我执行rails srake db:migratebundle exec rackup,则会出现此错误:

/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require': dlopen(/Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.20/lib/mysql2/mysql2.bundle

抱歉不要破坏上面的代码(我不喜欢这个卷轴),但我不想阻碍对问题的理解。

OS: Mac OS X Yosemite - 10.10.3
Ruby -v: ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
Rails -v: Rails 4.2.1
Mysql2 version: mysql2 (0.4.3, 0.3.20, 0.3.18)

我尝试过(在不同的语气中分开的命令):

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

其他信息:

命令:

otool -L /Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.18/lib/mysql2/mysql2.bundle

返回

/Library/Ruby/Gems/2.0.0/gems/mysql2-0.3.18/lib/mysql2/mysql2.bundle:
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/libruby.2.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)
    /usr/local/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
    /usr/lib/libssl.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
    /usr/lib/libcrypto.0.9.8.dylib (compatibility version 0.9.8, current version 0.9.8)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

PS:bundle工作正常,没有错误

韩国社交协会

2 个答案:

答案 0 :(得分:4)

<强> [解决]

@SeanHuber建议我使用mysql2 -v 0.3.18

我卸载了版本0.3.20 MySQL2:

sudo gem uninstall mysql2 -v 0.3.20

之后我安装了版本0.3.18

sudo gem install mysql2 -v '0.3.18'

在我的Gemfile中:

gem 'mysql2', '~> 0.3.18'

之后,捆绑工作。 我需要更新一些宝石,作为设计。 结果,我将ruby升级到2.2.3。

现在,一切正常。

结论: mysql2 -v 0.3.20很糟糕。

感谢@SeanHuber给我指路。

答案 1 :(得分:0)

请注意以下步骤,因为您缺少进行数据库adpater连接所需的一些必需库:

sudo apt-get install libmysql-ruby libmysqlclient-dev
sudo apt-get install libmysqlclient-dev
gem uninstall mysql
bundle install