Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from dteoh/mysql2-gem-install.md
Created September 27, 2022 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdanRada/f9f84315b18b96111d10970f52563c37 to your computer and use it in GitHub Desktop.
Save bogdanRada/f9f84315b18b96111d10970f52563c37 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