13

Getting the following error after running rake db:migrate

rake aborted!
LoadError: dlopen(/Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle, 9): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/scott/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10/lib/mysql2/mysql2.bundle
/Users/scott/Google Drive/playground/myApp/myApp/config/application.rb:21:in `<top (required)>'
/Users/scott/Google Drive/playground/myApp/myApp/Rakefile:4:in `<top (required)>'

What does the libssl refer to?

s89_
  • 1,533
  • 3
  • 25
  • 40
  • Can you show us code sample, what have you tried so far? – Anand Jul 10 '18 at 12:40
  • So far I have tried most solutions on stackoverflow - 1) adding mysql to PATH 2) installing newer gem version of mysql2 (0.4.10) since my installation instructions asked for 0.4.5 3) and lastly, this solution - https://afshinm.name/2016/02/05/how-to-fix-library-not-loaded-libmysqlclient-18-dylib-in-mac-os-x/ – s89_ Jul 10 '18 at 12:44
  • @Gabbar what code sample would you like, and how would that help? I'm installing a Rails App from github which I'd like to contribute to. – s89_ Jul 10 '18 at 12:45
  • Are you on Mac? Maybe use `brew`, or your preferred package manager to install libssl. – Kris Jul 10 '18 at 14:11
  • Yeah on a Mac. Tried that also, didn't work. – s89_ Jul 10 '18 at 15:20

7 Answers7

29

First uninstall the mysql2 gem:

gem uninstall mysql2

Make sure you installed openssl:

brew install openssl

It will print out some notes. We are interested in this part:

For compilers to find this software you may need to set:
LDFLAGS:  -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

Then you can re-install mysql2 gem like this:

gem install mysql2 -v 0.4.10 -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib

You should be good to go.

Michael Erb
  • 291
  • 3
  • 3
  • 1
    Thanks, @michael. I was trying to fix a bug for weeks now and the solution you provided is the one that worked. What a relief, man! – Mickey Mahoney Aug 29 '18 at 23:50
  • This is the correct answer, though I had to run `brew reinstall openssl` to see these notes since I already had it installed. – Trevor Elwell Apr 02 '19 at 06:43
  • 1
    This is almost right answer for me. After installing check the output: ```For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ``` use those flags listed in output when installing mysql2 gem – greggmi Apr 24 '20 at 23:09
8

Following fix solves the issue

   ==> cd /usr/local/Cellar/openssl/1.0.2s/lib/

==> sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109
2

So the answer to my own question was the following - out of the 5 or so other solutions on stackoverflow, this is the only one that worked:

brew install openssl

cd /usr/local/Cellar/openssl/1.0.1f/lib

sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/

Full solution here - https://mithun.co/hacks/library-not-loaded-libcrypto-1-0-0-dylib-issue-in-mac/

s89_
  • 1,533
  • 3
  • 25
  • 40
  • NO! :(. I followed these commands and it installed here the MySQL 8.0 locally, but my project need to be with MySQL 5.7 version. Therefore, these commands completely messes up my project and **it was required to reinstall the mysql completely**. – Victor Mar 29 '21 at 20:33
1

In my case just uninstalling and installing the mysql2 gem did the trick

$ gem uninstall mysql2
$ bundle install 
> Fetching mysql2 0.4.10
> Installing mysql2 0.4.10 with native extensions
Hector Correa
  • 26,290
  • 8
  • 57
  • 73
1

just one command:

gem pristine mysql2

then i fix this problem

Cool.wen
  • 2,559
  • 1
  • 7
  • 4
  • Well, it worked here! This should be marked as the right answer. Simple, but effective, like ALL things SHOULD be. Thanks. – Victor Mar 09 '21 at 04:12
  • Well... I remove my words, this installed MySQL version 8.0 here and bugged everything. On my case I still need to keep with the MySQL version 5.7. – Victor Mar 29 '21 at 20:25
0

For users of rbenv:

 brew uninstall openssl
 brew install rbenv/tap/openssl@1.0

 gem uninstall mysql2
 gem install mysql2 -v '0.4.10' -- --with-opt-dir="$(brew --prefix rbenv/tap/openssl@1.0)"
Matthew Hinea
  • 1,872
  • 19
  • 31
0

For me, the later versions of mysql2 (0.5.3 in my case) needed openssl1.1. After doing this, it worked for me:

$  cp /usr/local/Cellar/openssl@1.1/1.1.1j/lib/libssl.1.1.dylib /usr/local/lib
$  cp /usr/local/Cellar/openssl@1.1/1.1.1j/lib/libcrypto.1.1.dylib /usr/local/lib
bryanmac
  • 38,941
  • 11
  • 91
  • 99