Cannot install gem mysql2 on OSX 10.8.4 #383

anthonyalmighty opened this Issue Jun 25, 2013 · 7 comments


None yet

5 participants


I'm 3+ full days into trying to get this to work. I'm really hoping someone can help and/or identify this is a bug and needs to be fixed.

Version = 2.0.0-p195
Installed @: ~/.rbenv/versions/2.0.0-p195

OSX = 10.8.4

Downloaded from (I tried homebrew but
Version = 5.6.12 x64
Installed @: /usr/local/mysql-5.6.12-osx10.7-x86_64/
Symlink: /usr/local/mysql -> Installed @

XCODE = 4.6.3
Command Line Tools: Installed

sudo gem install mysql2 yields

'gcc' in terminal yields: i686-apple-darwin11-llvm-gcc-4.2:

mysql_config --cflags: --cflags [-I/usr/local/mysql-5.6.12-osx10.7-x86_64/include -Wno-null-conversion -Os -g -fno-strict-aliasing -arch x86_64]

sudo env ARCHFLAGS="I/usr/local/mysql-5.6.12-osx10.7-x86_64/include -arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include


Why is it that even though I am passing in the right flags that it's still complaining it can't find mysql.h? It's there, and the /usr/local/mysql/include symlink resolves to the appropriate directory, and I can see the header files.

sudo find / -name mysql.h
/usr/local/mysql-5.6.12-osx10.7-x86_64/include/mysql.h #<-- it's there!!!!!

This issue is literally littered across the internet, going back to 2009 and still persisting today. These are the links to the posts that I have tried.

The lis of links goes on and on....





I just uninstalled the mysql installation from the DMG and installed via brew install mysql

I then re-ran the 'gem install' command:

sudo env ARCHFLAGS="-I/usr/local/mysql/include -Os -g -fno-strict-aliasing -arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions with: '--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config'

I looked at the mkmf file:

sudo vim ~/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/ext/mysql2/mkmf.log

It told me it didn't like the compiler switches '-Wno-null-conversion -Wno-unused-private-field'

Because of this article ( I cracked open the mysql_config file here:

sudo vim /usr/local/mysql/bin/mysql_config

I '/ -Wno' searched and found two lines where default cflags and cxxflags were set, which included these switches. I deleted these from the mysql_config file and then re-ran 'gem install' as before....

Defcon5:PowerCtrl anthonyalmighty$ sudo env ARCHFLAGS="-I/usr/local/mysql/include -Os -g -fno-strict-aliasing -arch x86_64" gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions with: '--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include --with-mysql-config=/usr/local/mysql/bin/mysql_config'
This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed

BANG! I really hope this helps others, and I'm going to link these articles together so that someone could benefit. I spent an extraordinary amount of time trying to get this to work; I hope you don't have to go through the same.

filib commented Jun 26, 2013

Workaround: See Update

I've also run into some problems with this in the last few days. I'm trying to install mysql2 with the following command. It's the same as above but explicitly points to the Homebrew Cellars.

env ARCHFLAGS="-I/usr/local/Cellar/mysql/5.6.12/include -Os -g -fno-strict-aliasing -arch x86_64" gem install mysql2 -- \
--with-mysql-dir=/usr/local/Cellar/mysql/5.6.12 \
--with-mysql-lib=/usr/local/Cellar/mysql/5.6.12/lib \
--with-mysql-include=/usr/local/Cellar/mysql/5.6.12/include --with-mysql-config=/usr/local/Cellar/mysql/5.6.12/bin/mysql_config 

But I keep getting an error about mysql.h being missing, despite being in the include directory.

checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... no
checking for mysql.h... no
checking for mysql/mysql.h... no
mysql.h is missing.  please check your installation of mysql and try again.

Anyone know a way to debug this? At a bit of a loss here.


I also managed to fix this by removing the following cflags from mysql_config.

 -Wno-null-conversion -Wno-unused-private-field

Thanks @anthonyalmighty!


Should this be escalated to the brew folks?

@filib filib referenced this issue in Homebrew/legacy-homebrew Jun 26, 2013

mysql brew's mysql_config has invalid compiler flags #20822

filib commented Jun 26, 2013

@sodabrew I raised an issue (Homebrew/legacy-homebrew#20822) but maybe there's a better place to report this.


Thanks for the nice solutions posted, that will help people searching for this issue! I'll close the bug here, since we shouldn't need to change anything on the mysql2 side.

@sodabrew sodabrew closed this Jun 26, 2013

note to future searchers, you may need a symlink in /usr/bin/gcc-4.2 - if this is missing, it may report mysql.h is missing but it isn't.. it's gcc that isn't running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment