Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2019 01:18
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Installing mysql2 gem

Installing mysql2 gem

This is always an annoying process, especially when you are setting up a new computer. I assume you are using macOS + homebrew. I also assume that you want to run an older version of MySQL (although the instructions should be adaptable).

Installing MySQL

$ brew install mysql@5.7 # change the version if needed
$ brew install openssl@1.1 # you probably already have this installed

At the end of each install, brew gives you some info. You can always see this again with:

$ brew info mysql@5.7

Installing the gem

Whether installing the gem through bundler or directly with the gem install command, you will need to configure some build flags. The values of these flags come from whatever the brew info command tells you. Please customize the flag values below as needed.

with bundler

$ bundle config build.mysql2 --with-mysql-config=/usr/local/opt/mysql@5.7/bin/mysql_config --with-ldflags="-L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/mysql@5.7/lib" --with-cppflags="-I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/mysql@5.7/include"
$ bundle install

with gem install

Change the gem version as needed.

gem install mysql -v '0.5.2' -- --with-mysql-config=/usr/local/opt/mysql@5.7/bin/mysql_config --with-ldflags="-L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/mysql@5.7/lib" --with-cppflags="-I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/mysql@5.7/include"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment