I tried several ideas ... none of them worked ... I\'m just trying to install mysql2 as a gem. My mysql is working, but every time my system says, that mysql.h is missing .
Installing a gem sometimes involves compiling source. In this case the MySQL gem needs to create the ruby interface by compiling the C code -- you most likely need to install the MySQL development files.
(missed the OSX reference earlier)
You need to install the development headers for mysql, using brew you might need to install a lower version than 8 since some header files are removed from this distribution. For instance the my_global.h
is removed, so if you code uses this header you will be forced to install a previous version then 8.
Header File Dependencies
We have started cleaning up header files dependencies, i.e. work on “include what you use” and on reorganizing header files to remove build dependencies. We have fixed ambiguous include paths; almost all should now be from the root. Incrementality has increased a lot after e.g. my_global.h went away, and sql_class.h was also reduced a fair bit in weight. Shipped client headers are self-contained and much more sane. For example, client headers are now platform independent (no difference between 32- and 64-bit Linux).
brew install mysql@5.7 mysql-client@5.7
If you're using the standard XAMPP this could be the problem, you could probably need to install xampp-devel which is the development package for xampp, this distribution contains mysql headers *.h
files as well as other related sources, you can find older versions in here.
you can than copy the include
directory in your /Applications/XAMPP/xamppfiles
then install gem using this command:
sudo gem install mysql2 -v 0.3.21 -- --with-mysql-config=/Applications/XAMPP/xamppfiles/bin/mysql_config --with-mysql-include=/Applications/XAMPP/xamppfiles/lib/include/ --no-ri --no-rdoc
this version worked for me, and don't need to include --with-mysql-dir
if you specify mysql_config
path, and then you should get a similar output:
This could take a while...
Successfully installed mysql2-0.3.21
Parsing documentation for mysql2-0.3.21
Installing ri documentation for mysql2-0.3.21
Done installing documentation for mysql2 after 0 seconds
1 gem installed
you may also need to provide rails with the correct version of libmysqlclient
, here is an example using Symlink:
sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /usr/local/lib/libmysqlclient.18.dylib
Don't forget in update bundle packages.
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