views:

290

answers:

2
+1  A: 

I had this same problem and solved this way:

  1. make sure you have installed only the gem ruby-mysql and not the gem mysql. For me, now:

    $ gem list --local | grep mysql

    ruby-mysql (2.9.2)

  2. If that is not the case, uninstall

    $ sudo gem uninstall mysql

(I uninstalled every gem with mysql in its name) and then reinstalled ruby-mysql.

In my case, because I have mysql installed in a usb disk the installation command was:

sudo env ARCHFLAGS="-arch i386" gem install ruby-mysql   --  

--with-mysql-config=/Volumes/usb/opt/bin/osx/mysql/bin/mysql_config

--with-mysql-lib=/Volumes/usb/opt/bin/osx/mysql/lib/      

--with-mysql-dir=/Volumes/usb/opt/bin/osx/mysql

(and I was using the 32bits binary for MacOs, don't know if that applies for you)

Finally, my ruby test program was

require 'rubygems'
require 'mysql' 


dbh = Mysql.real_connect('localhost', 'root', 'your password', 'TEST')


res =  dbh.query("select * from Persons;");

puts res.class

res.each do |row|
    puts row.join(" ")
end
cibercitizen1
@cibercitizen1For me right now its:--mysql (2.8.1)
piemesons
+1 this does, in fact, resolve the issue.
pilcrow
A: 

Short answer:

  1. Remove mysql-ruby
  2. Rebuild mysql-ruby
  3. Reinstall mysql-ruby.

Alternative answer

  1. Remove mysql-ruby
  2. Install ruby-mysql
    The pure ruby MySQL protocol client.

Longer Explanation:

This just happened to me. My 2.8.1 mysql-ruby bindings had been built against libmysqlclient.so.15, and worked fine until I upgraded my MySQL installation and replaced that client library with .so.16. Rebuild resolved this issue.

The 3rd-party gem you used (I used it, too) introduces faulty logic in the mysql.rb file it supplies to trap an error on Windows systems. Notice that in the excerpt you posted, that this mysql.rb file does not re-raise the LoadError on non-Windows platforms. Bummer.

Edit

I contacted the gemspec author, and he has corrected the error! (2010-05-25) With luck no one else will be baffled by this silent failure.

pilcrow