Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL2 Gem is failing following a MacBookPro OS upgrade #1250

Closed
josephmo opened this issue Mar 21, 2022 · 2 comments
Closed

MySQL2 Gem is failing following a MacBookPro OS upgrade #1250

josephmo opened this issue Mar 21, 2022 · 2 comments
Milestone

Comments

@josephmo
Copy link

OS: MacOS Monte[r](https://stackoverflow.com/questions/tagged/ruby-on-rails)ey-version 12.3
Rails 7.0.2
Ruby 3.1.0
MySQL gem: mysql2 (0.5.3) (from Gemfile.lock)

My app Rails development server was running great, until Apple said I should update to Monterey version 12.3, which included an xcode update.

I next tried to run the db migrate:

rake db:migrate
To which I received the following message:

rake aborted!
LoadError: dlopen(/Users/joseph-mac/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle, 0x0009): Library not loaded: libssl.1.1.dylib
  Referenced from: /Users/joseph-mac/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle
  Reason: tried: 'libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file), '/Users/joseph-mac/ProxLearn/Development/PLIConnectV2/repositories/pli2_tw/libssl.1.1.dylib' (no such file), '/usr/local/lib/libssl.1.1.dylib' (no such file), '/usr/lib/libssl.1.1.dylib' (no such file) - /Users/joseph-mac/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.bundle

My original MySQL2 gem was built as follows:

gem install mysql2 -- --with-opt-dir=/opt/homebrew/opt/[email protected] –with-mysql-dir=/opt/homebrew/opt/mysql
And as far as I remember, this is where homebrew was. I tried looking for the files:

/opt/homebrew/opt/[email protected]
And the response was:

no such file or directory: /opt/homebrew/opt/[email protected]
The following:

ls -l /opt/homebrew
Produces:

ls: /opt/homebrew: No such file or directory
Which means that the OS upgrade eradicated the /opt/homebrew, or at least eradicated the Symlinks to it.

However, doing:

brew list
Produces:

==> Formulae
...  [email protected]
...  openssl@3

Digging further into it, it looks like the homebrew real folder, is at:

/usr/local/Cellar
And I found the following folders:

/usr/local/Cellar/[email protected]/1.1.1m/include
/usr/local/Cellar/[email protected]/1.1.1m/lib

Great, so off to build the MySQL2 gem again:

gem install mysql2 -- --with-opt-dir=ls -l /usr/local/Cellar/[email protected]/1.1.1m/lib --with-cppflags=-I/usr/local/Cellar/[email protected]/1.1.1m/include

And the response is:

Building native extensions with: '--with-opt-dir=ls -l /usr/local/Cellar/[email protected]/1.1.1m/lib --with-cppflags=-I/usr/local/Cellar/[email protected]/1.1.1m/include'
This could take a while...
Successfully installed mysql2-0.5.3
1 gem installed

But, when I run:

rake db:migrate
I get the exact same error I started with.

When I do:

which openssl
The response is:

/usr/bin/openssl
Which is an executable, not a folder.

I tried uninstalling the MySQL2 gem before every step, and then re-installing, and then re-bundling. Same error.

Any ideas?

@josephmo
Copy link
Author

Looks like the OS update, wreaked havoc on all the homebrew links and file locations. I figured a fix.

brew update --preinstall
brew install [email protected]

Then when this is done, add the following to ~/.zshrc:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"

And adding the following line, as the last statement in ~/.zshrc:

export PATH="/usr/local/opt/[email protected]/bin:$PATH"

To make sure the homebrew installed [email protected] is the one to go, instead of the one installed in /usr/local/bin

Then restart your terminal, and do the following:

gem install mysql2 -- --with-opt-dir=/usr/local/opt/[email protected] –with-mysql-dir=/usr/local/opt/mysql

@sodabrew
Copy link
Collaborator

Further improved in #1303 and #1305 - will be included in mysql2 0.5.5.

@sodabrew sodabrew added this to the 0.5.5 milestone Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants