Topic: MySQL gem ('gem install mysql') fails on Centos 4.4 (and RedHat too).

I'm just posting this work-around, as others may come across the same problem when installing the MySQL gem on to Centos 4.4 (or other distros).

The solution to the problem (below) is simply to make symbolic links to MySQL's lib and include directories.  There is probably a more elegant solution.  Please reply if you know how to change the paths which gem searches, or why MySQL is in the wrong place on RedHat.


Solution:

root@centos4:~# ln -s /usr/include/mysql /usr/local/include/
root@centos4:~# ln -s /usr/lib/mysql /usr/local/lib/


Problem: (Full text to help those googling this)

root@centos4:~# gem install mysql

Select which gem to install for your platform (i686-linux)
1. mysql 2.7.1 (mswin32)
2. mysql 2.7 (ruby)
3. mysql 2.6 (ruby)
4. mysql 2.5.1 (ruby)
5. Cancel installation
> 2

Building native extensions.  This could take a while...
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/ruby
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib

ERROR:  While executing gem ... (RuntimeError)
    ERROR: Failed to build gem native extension.
Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.


Results logged to /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out