El Capitan upgrade: Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
Asked Answered
R

6

35

Error:

/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `require': dlopen(/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
  Reason: image not found - /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle

In Gemfile: gem 'mysql2'

$ ls -al /usr/local/lib/libmysql*

lrwxr-xr-x  1 askar  admin  49 Nov 13 10:48 /usr/local/lib/libmysqlclient.20.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.20.dylib
lrwxr-xr-x  1 askar  admin  42 Nov 13 10:48 /usr/local/lib/libmysqlclient.a -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.a
lrwxr-xr-x  1 askar  admin  46 Nov 13 10:48 /usr/local/lib/libmysqlclient.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.dylib
lrwxr-xr-x  1 askar  admin  37 Nov 13 10:48 /usr/local/lib/libmysqld.a -> ../Cellar/mysql/5.7.9/lib/libmysqld.a
lrwxr-xr-x  1 askar  admin  44 Nov 13 10:48 /usr/local/lib/libmysqlservices.a -> ../Cellar/mysql/5.7.9/lib/libmysqlservices.a

$ ls -al /usr/local/Cellar/mysql/5.7.9/lib/

total 84392
drwxr-xr-x   9 askar  admin       306 Nov 12 22:16 .
drwxr-xr-x  14 askar  admin       476 Nov 13 10:48 ..
-r--r--r--   1 askar  admin   3780168 Nov 13 10:48 libmysqlclient.20.dylib
-r--r--r--   1 askar  admin   4280752 Nov 12 22:16 libmysqlclient.a
lrwxr-xr-x   1 askar  admin        23 Nov 12 22:16 libmysqlclient.dylib -> libmysqlclient.20.dylib
-r--r--r--   1 askar  admin  35126528 Nov 12 22:16 libmysqld.a
-r--r--r--   1 askar  admin      9048 Nov 12 22:16 libmysqlservices.a
drwxr-xr-x   3 askar  admin       102 Nov 13 10:48 pkgconfig
drwxr-xr-x  43 askar  admin      1462 Nov 12 22:17 plugin
drwxr-xr-x  43 askar  admin      1462 Nov 12 22:17 plugin

As you see I'm having libmysqlclient.20.dylib, it's 20 not 18, otherwise I'd follow the solution here.

I've recently upgraded to El Capitan but not sure it that's the cause.

UPDATE:

Thanks to @Rashmirathi for the hint to re-install the gem.

Just wanted to note, I needed also to specify in Gemfile as:

gem 'mysql2', '~> 0.3.18'

Otherwise I had error:

Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

But finally I got error:

Mysql2::Error
Your password has expired. To log in you must change it using a client that supports expired passwords.

Which is solved by setting up a password again:

SET PASSWORD=PASSWORD('your_password');
Rodroda answered 18/11, 2015 at 4:48 Comment(1)
I am facing the same issue immediately after upgrading to El Captain. Not sure why apple hasnt fixed the issue yet. Even after upgrading mysql and MySQL-python via pip the issue persists.Conger
E
54

I was getting the same issue earlier on, I fixed it by reinstalling the gem mysql2.

Extension answered 18/11, 2015 at 10:24 Comment(3)
I did some update on my post you might be interested in... ;)Rodroda
For future reference, I got to this thread due to similar problems in Python and pip, and this solution also worked (pip uninstall MySQL-python && pip install MySQL-python).Mockery
If there is only one version of the mysql installed, then re installing is only the solution.Enwomb
T
42

this will solve your problem:

gem pristine mysql2

solution by Cesar Sulbarán

Toenail answered 19/11, 2015 at 1:2 Comment(0)
K
23

For those on OS X El Capitain or more, this fix my problem:

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

For more info https://mcmap.net/q/173801/-rails-mysql-on-osx-library-not-loaded-libmysqlclient-18-dylib

Krall answered 14/3, 2016 at 17:57 Comment(1)
for me this is a more generic solution: ln -nfs /usr/local/lib/libmysqlclient.dylib /usr/local/lib/libmysqlclient.18.dylibTexas
I
5

I had an analogous problem in python: libmysqlclient.20.dylib instead of 18 on El Capitan. pip install --upgrade mysql fixed it, but only works in python2.

Imes answered 15/1, 2016 at 19:41 Comment(2)
Relevant lib is installed as pip install MySQL-python. However --upgrade didn't work for me as I had latest version of the lib which has been broken for some reason. Combination uninstall + install worked for me.Siddra
@Siddra this worked for me. I got the errors from updating/upgrading brew.Argillaceous
A
4

I'm using Homebrew so I've fixed this problem by clearing up everything step by step:

  1. Comment out the mysql2 gem in in the Rails app Gemfile

    "# gem 'mysql2'"

  2. Remove mysql2 gem from bundle

    bundle install

  3. Uninstall the mysql2 gem (all versions)

    gem uninstall mysql2

  4. Update Homebrew

    brew update

  5. Uninstall all versions of mysql

    brew uninstall --force mysql

  6. Reinstall mysql

    brew install mysql

  7. Uncomment mysql2 gem in Gemfile

    gem mysql2

  8. Add mysql2 to bundle

    bundle install

This approach might be a bit overkill but feels clean to me.

Allot answered 25/8, 2016 at 14:15 Comment(0)
P
1

Just want to chime in here- I just had the same problem with the libmysqlclient.18.dylib 18-20 difference. reinstalling the mysql gem (a dependency of the activerecord-mysql-adapter) made the difference. reinstalling mysql2 did nothing.

editing to clarify: my error message traced back to my mysql gem, but i found this thread via searching so i'm including it here:

Please install the mysql adapter: `gem install activerecord-mysql-adapter` (dlopen(/Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle, 9): 
Library not loaded: /usr/local/lib/libmysqlclient.18.dylib 
Referenced from: /Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle
Reason: image not found - /Users/eriks/.rvm/gems/ruby-2.1.4/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle) (LoadError)
Posh answered 24/11, 2015 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.