Search code examples
ruby-on-railsruby-on-rails-4rubygemsbundlemysql2

Error on load "libmysqlclient.18" - gem mysql2


After I executed bundle, I don't get to use rails nor rake. If I execute rails s or rake db:migrate or bundle exec rackup, I have this error:

/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

Sorry not break the code above (I don't like this scroll), but I did not want to hinder the understanding of the problem.

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)

I tried (separated commands in different momments):

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

Other info:

The command:

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

return

/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 works fine, no errors

Tks


Solution

  • [SOLVED]

    @SeanHuber suggested that I use mysql2 -v 0.3.18

    I uninstalled the version 0.3.20 MySQL2:

    sudo gem uninstall mysql2 -v 0.3.20
    

    After that I installed the version 0.3.18:

    sudo gem install mysql2 -v '0.3.18'
    

    And in my Gemfile:

    gem 'mysql2', '~> 0.3.18'
    

    After that, the bundle works. I need to update some gems, as devise. Consequence, I did the ruby upgrade to 2.2.3.

    Now, all works.

    Conclusion: mysql2 -v 0.3.20 is bad.

    Thanks @SeanHuber to show me the way.