Ruby, Mysql, CentOS 5, and 64-bit

Posted by Michael on January 19, 2009 in SQL, Systems

I have lately switched away from Ubuntu as my desktop and started using CentOS 5.2 because I wanted better support for a lot of RAM and virtualization (where I can quickly commission Linux servers to build out my testbed of target environments).  With the change, I also make the leap into pure 64-bit libraries with little to no 32-bit libraries installed.  There’s been a few sticky points to push through and one of them is getting Mysql and the appropriate mysql gems installed.  This quick post shows the way.

My System


I am running CentOS 5.2 64-bit. Or more succinctly:

2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 11:57:43 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

The Problem

If you simply execute:

sudo gem install mysql

You’ll get the following errors on a 64-bit system:

$ sudo gem install mysql
Building native extensions.  This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb install mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
*** 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

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

After digging into the gem options and logs a bit and looking at where mysql actually got installed, I discovered that it was hitting all the locations the 32-bit version would normally install to, but not the 64-bit version, which ends up in /usr/lib64/mysql.

Installing the Ruby gems

To properly install the Ruby gems for mysql, you’ll have to explicitly tell the gem where the mysql config is and it will then handle all the rest.

gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config

With that, you should see the following:

Building native extensions.  This could take a while...
Successfully installed mysql-2.7
1 gem installed

Check it out with:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mysql'
=> true
irb(main):003:0> quit

Life is good.

  • david
    heh, nevermind, got it.
    % sudo yum install mysql-devel
    sudo gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config
    Building native extensions. This could take a while...
    Successfully installed mysql-2.7
    1 gem installed

    schweet
  • david
    % uname
    2.6.18-92.el5 #1 SMP Tue Jun 10 18:51:06 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux

    % sudo gem install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config Building native extensions. This could take a while...
    ERROR: Error installing mysql:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby extconf.rb install mysql -- --with-mysql-config=/usr/lib64/mysql/mysql_config
    checking for mysql_ssl_set()... no
    checking for mysql.h... no
    checking for mysql/mysql.h... no
    *** 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/bin/ruby
    --with-mysql-config


    Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/mysql-2.7 for inspection.
    Results logged to /usr/lib64/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

    looks like this is killing it:
    less /usr/lib64/ruby/gems/1.8/gems/mysql-2.7/mkmf.log
    error: mysql/mysql.h: No such file or directory

    where/how did you get the mysql headers?
  • James B. Byrne
    Although it does not appear as a dependency anywhere, to successfully build the mysql gem on Centos-5.3 x86_64 one requires that zlib-devel.x86_64 be installed as well.
  • mwlang88
    @ Mathieu: Excellent. Glad you got it working. You can drop the useless 32-bit packages or ensure 64-bit packages when installing by explicitly specifying the architecture when installing/uninstalling packages. For example, instead of simply


    sudo yum install mysql mysql-devel mysql-server


    You run this:


    sudo yum install mysql.x86_64 mysql-dev.x86_64 mysql-server.x86_64
  • ok, i just had to look at the mkmf.log file

    gcc was missing ;)

    and

    [root@centos52-64 ~]# gem install mysql -- --with-mysql-conf=/usr/lib64/mysql/mysql_config --with-mysql-lib=/usr/lib64/mysql/

    is working, and all parameters were required.
  • Hi,

    I run the exact same setup. 5.2, same kernel, 64bit. but it does not work.
    same error

    Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/mysql-2.7 for inspection.
    ruby extconf.rb install mysql -- --with-mysql-conf=/usr/lib64/mysql/mysql_config\nchecking for mysql_query() in -lmysqlclient... no
    checking for main() in -lm... no
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lz... no
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lsocket... no
    checking for mysql_query() in -lmysqlclient... no
    checking for main() in -lnsl... no
    checking for mysql_query() in -lmysqlclient... no


    any idea what else I could try?
    I deleted the remaining stuff in gem dir and start over same thing.

    I weird thing I'm not happy with is duplicate rpm 32bit and 64bit
    is it a must under centos or there is a way to clean up the useless 32 bit stuff?

    thanks
blog comments powered by Disqus

More

Read more posts by Michael

About the Author

A software developer and network engineer for over 25 years. Currently developing Microsoft Windows desktop applications with Delphi and web services with Ruby, Ruby on Rails, Ramaze and Javascript. Web services are hosted on CentOS and Ubuntu servers under either Xen or VMWare powered via Apache, passenger, mysql and postgresql.