I updated all the packages I installed with Homebrew. MySQL got upgraded to 5.6.12 (from 5.5.27 or so):
$ mysql --version
mysql Ver 14.14 Distrib 5.6.12, fo
I had the same problem, I managed to fix it. I did a lot of things, and I don't know for sure what it was, but going to MySQL 5.6.10 seems to have worked.
Uninstall MySQL 5.6.12:
brew unlink mysql
brew uninstall mysql
Go to the homebrew directory:
cd /usr/local
Go to version 5.6.10 (you can find a list of versions by running brew versions mysql:
git checkout 48f7e86 Library/Formula/mysql.rb
Then install mysql again:
brew install mysql
And now gem install mysql2 works for me.
I've also installed mysql from source (brew install mysql --build-from-source), but that didn't solve it, but might be part of the solution.
This also seemed to work for me. It forces the gem to compile against 5.6.10.
bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config
Related answer: https://stackoverflow.com/a/9360181
just ;)
gem install mysql2 -- --with-mysql-config=/usr/local/Cellar/mysql/5.6.10/bin/mysql_config
The top answer here is out-of-date... the brewers have fixed mysql:
brew update
brew upgrade mysql
gem install mysql2
This will update mysql to the latest version, which seems to work fine with the mysql2 gem on OSX.
I would recommend this answer instead: mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew
The problem is with the compiler settings in Homebrew's version of MySql. Original answer found here: http://www.randomactsofsentience.com/2013/05/gem-install-mysql2-missing-mysqlh-on-os.html
I had to specify the ldflags and cppflags for it to compile correctly, like this:
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include