Install DataMapper MySQL adapter on Mac OS X (10.6.6)

I’ve just installed MySQL 5 from mysql-5.5.9-osx10.6-x86_64.dmg package, see MySQL download website or mirrors.
This package installs MySQL in /usr/local/mysql (symlink to mysql-5.5.9-osx10.6-x86_64).
When I wanted to install DataMapper MySQL driver, I ran into the following error:

$ sudo gem install dm-mysql-adapter --no-rdoc --no-ri
Fetching: data_objects-0.10.3.gem (100%)
Fetching: do_mysql-0.10.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing dm-mysql-adapter:
	ERROR: Failed to build gem native extension.
/opt/ruby-1.9.1/bin/ruby extconf.rb
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.

This means while compiling the extension, compiler can’t find mysql librairies. It’s because they haven’t been installed in standard include folders. They actually are in /usr/local/mysql.
To indicate to the compilation process to check this folder you need to add the following parameter to the command line:

$ sudo gem install dm-mysql-adapter --no-rdoc --no-ri -- --with-mysql-dir=/usr/local/mysql/

Building native extensions.  This could take a while...
Fetching: dm-do-adapter-1.0.2.gem (100%)
Fetching: dm-mysql-adapter-1.0.2.gem (100%)
Successfully installed do_mysql-0.10.3
Successfully installed dm-do-adapter-1.0.2
Successfully installed dm-mysql-adapter-1.0.2
3 gems installed

You’re done!

  • Eric

    Thank you. This worked!