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).
$ 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
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.
$ 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
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"