mysql.h is missing .... (Ruby on Rails, OSX)

Using a package manager like Homebrew or MacPorts makes it fairly straight-forward to fix this. The binary distribution of MySQL direct from Oracle and the one bundled with OS X itself does not have the development headers, of which mysql.h is one of them.

Homebrew would fix it like this:

brew install mysql

MacPorts is very similar:

sudo port install mysql

Both of these install libraries, a command-line client and the associated development headers for the libraries. Enabling the server is optional.

As an alternative, you can get the source direct from Apple and install it whatever way you see fit.

Generally Homebrew is the best way to go.


What worked for me in Mountain Lion Rails install(using Homebrew and RVM) was editing /usr/local/Cellar/mysql/5.XX.XX/bin/mysql_config and removing -Wno-null-conversion -Wno-unused-private-field from cxflags and cxflags options as follows:

Before:

cflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Wno-null-conversion -Wno-unused-private-field -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

After:

cflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!
cxxflags="-I$pkgincludedir  -Wall -Os -g -fno-strict-aliasing -DDBUG_OFF " #note: end space!

After that gem install mysql2 proceeded without hickups

Note: this is probably due to a change introduced to mysql_config after 5.6.10: http://bugs.mysql.com/bug.php?id=69645