I\'m setting up my development environment in the new macOS Sierra .
First of all, I installed Rbenv, Ruby (2.3.1)
I am here to share my fix, since the other answers didn't work.
For my environment, I need MySQL 5.6 so I had to use:
brew install mysql56
instead of brew install mysql
Bundle installing the mysql2 gem kept failing, until:
brew link mysql56
I also ran afterwards:
mysql.server start
The last step might be unnecessary, but just in case.
First, you should try 2 answer in here If you installed openssl but it still don't work. You should try to o refresh gems reference. A got the same issue and it worked for me.
gem source -r https://rubygems.org/
gem source -a https://rubygems.org/
So I ran into this similar issue and for me it turned out to be a wrong ruby version and incompatible MySQL version. I use ruby 2.3 on most of my projects but inherited a 2.1 project. Changing to rvm to use 2.1 got me a little further.
Then I found this: https://github.com/brianmario/mysql2/issues/603 that said you had to use mysql2 gem version greater than 0.3.17 with MySQL version 5.7
Updated gem to 0.3.17 and it fired right up. Hope this helps someone.
If none of the above works .. like in my case, doing this solved the issue
brew install openssl
FYI: i am using MacOS Catalina
Try installing xcode-select --install
I just had the same problem, tried all of the solutions listed above, then commenced to bang my head against they keyboard for a couple of hours.
I then thought to try and install/reinstall the Xcode Command Line Tools:
xcode-select --install
Once I did that the mysql2 gem installed w/ no problems. I hope that does the trick!