Skip to navigation [a]

November 1, 2007

Get the MySQL Ruby Gem working on Leopard //

Leopard is out and it’s generally good aside from a few minor hiccups, surprises and unexpected changes deeper down in the OS affecting the Unix core.

One such hiccup is that the native bindings that allow Ruby and MySQL to communicate are a bit harder to get working than in Tiger unless you happened to just go a straight upgrade to Leopard in which case they should still be working.

MySQL’s binaries should install just fine in Leopard, but be sure to stick with version 5.0.37 of the Community Server for the time being. The two newer builds appear to be broken. You can download version 5.0.37 from here: http://downloads.mysql.com/archives.php?p=mysql-5.0&v=5.0.37.

Once you’ve got that installed along with the Xcode Developer Tools (found on your Leopard DVDs in the Optional Installs folder) you are ready to fire up the Terminal and install the MySQL Gem. You’ll be prompted for your admin password after the first command.


sudo -s
ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql

If you’re on a PPC system, just replace `-arch i386` with `-arch ppc` and you should be good to go.

So say you…

This doesn’t work for me on my G4 PPC system. I get the same error I’ve seen others report when googling about this problem. By the way I had no problem on my other, Intel machine. Darn Apple for not including mysql for ruby! Here’s the error report Sorry, this comment system messes the formatting..

bash-3.2# sudo bash -c "ARCHFLAGS='-arch ppc' \
gem install mysql" -- --with-mysql-dir=/usr/local/mysql

Need to update 12 gems from 
http://gems.rubyforge.org

............

complete

Select which gem to install for your
platform (universal-darwin9.0)

1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. Skip this gem
6. Cancel installation

Building native extensions. This could take a while...
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

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... no  
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=/System/Library/Frameworks/Ruby.framework/
       Versions/1.8/usr/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
/Library/Ruby/Gems/1.8/gems/mysql-2.7
for inspection. Results logged to
/Library/Ruby/Gems/1.8/gems/mysql-2.7/gem_make.out

Mike O'Connor Mike O'Connor November 5, 2007

Mike - what version of MySQL do you have installed? What about the Xcode tools? I’m assuming you’re also using Tiger (10.4)? Or Leopard on the G4?

Scott Scott November 5, 2007

I’m using Leopard Server with its supplied MySQL and XCode on this Dual 1GHz G4 (which runs Leopard surprisingly well with its 1.5GB RAM) But getting the mysql extension on it is a big problem (and was with Tiger too)

Mike O'Connor Mike O'Connor November 6, 2007

Hm. Interesting. Might be related to the fact that MySQL is not in the usual install location. I could have sworn that an older build of Leopard did include the MySQL gem by default. I remember testing it and checking what gems came fresh out of the box.

My Leopard Server disc hasn’t arrived yet but unless you find an answer in the meantime, I’ll make a note to check on that when it does.

Scott Scott November 6, 2007

Mike - I took at look at Leopard Server, and although I haven’t actually installed it anywhere (yet), MySQL is installed under the /usr directory path. I think you should be able to compile the MySQL Ruby bindings by using --with-mysql-dir=/usr.

if you do happen to try it and it works - let me know and I will update the post so other people might benefit from that knowledge.

Scott Scott November 8, 2007

When you get to the bottom you go back to the top of the slide… or check out our B-sides

It’s all interconnected …On A Long Piece Of String

Feeds //

Get social and don’t be a lurker

Elsewhere // Click to view

11