Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active July 11, 2023 02:11
Show Gist options
  • Save fernandoaleman/12698634824f5d5c00ab57b72ee2ad52 to your computer and use it in GitHub Desktop.
Save fernandoaleman/12698634824f5d5c00ab57b72ee2ad52 to your computer and use it in GitHub Desktop.
Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Catalina with MySQL 5.7.

Solution

Make sure openssl is installed on Mac via Homebrew.

brew install openssl

Install mysql2 gem.

gem install mysql2 -v '0.5.3' -- --with-mysql-config=$(brew --prefix [email protected])/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
@andreionut
Copy link

andreionut commented Oct 1, 2020

If you want to bundle mysql2 you need to set these flags via bundle config:
bundle config build.mysql2 --with-opt-dir=$(brew --prefix openssl)

On my Mac OS Catalina (with MySQL 8) setting --with-cppflags generated this error:

clang: error: unsupported option '--with-cppflags=-I/usr/local/opt/openssl/include'

Credit to this comment.

@tylerdavisgit
Copy link

Did you ever find a workaround for this? I've been doing any and everything to get the mysql2 gem installed in a rails project with no luck. I'm at Catalina 10.15.7

@shakeel19
Copy link

I also had this problem in an old project. (already had installed openssl and [email protected])
upgrading bundler from 1.17.3 to 2.2.9 worked for me.

@nikos83
Copy link

nikos83 commented Aug 1, 2021

I've tried your different git for Mojave and worked for me:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

@chandimaj1
Copy link

I've tried your different git for Mojave and worked for me:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

worked for me as well . been searching the internet for over 4 hours. MacOs Big Sur 11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment