Skip to content

Instantly share code, notes, and snippets.

@dteoh
Created November 22, 2019 01:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dteoh/d1f5f908914156754819b37e286849b3 to your computer and use it in GitHub Desktop.
Save dteoh/d1f5f908914156754819b37e286849b3 to your computer and use it in GitHub Desktop.
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