Re: undefined method `each' for #<Mysql:0x3874b20>

60 views
Skip to first unread message

Nick

unread,
Aug 24, 2006, 10:10:17 AM8/24/06
to rubyonra...@googlegroups.com
I'm having EXACTLY the same problem however I'm running Apache 2. The
first call works however if I refresh the page, it no longer works (or
any other call to the database) and I get:

undefined method `each' for #<Mysql:0x342fca4>

I also run MSSQL server on this machine and if I point the database.yml
to that instead (took a lot of setting up but finally got it working),
it works perfectly. Which is odd...

Any help greatly appreciated.

Nick

--
Posted via http://www.ruby-forum.com/.

Schultz

unread,
Aug 24, 2006, 10:14:12 AM8/24/06
to rubyonra...@googlegroups.com

I had this exact problem on a development based windows machine. The
problem was my libmysql.dll was not in sync with the MySQL server that i
had running. (I used instantrails for the mysql server and just
downloaded the 5.0 release dll from MySQL.com)
So i suggest if you have upgraded your MySQL install make sure that you
have the mysql gem re compiled so that it is linked with the same mysql
libraries.

Nick

unread,
Aug 24, 2006, 10:27:04 AM8/24/06
to rubyonra...@googlegroups.com
Hi and thanks for the very fast reply!

The funny thing is that I have only ever used MySQL v.5.0. I did however
use InstantRails at one point just to see what it was like. I didn't
like it, uninstalled it and reinstalled MySQL v.5.0.

Another odd thing is that I was having problems making Rails work at all
with the DB... I read somewhere that all I needed to do was copy the
libmySQL.dll file to my Windows\System32 directory. Which I did. Worked.
However, then I started experiencing these problems described above!

Finally, sorry to sound like a fool, but what exactly do you mean by
"have the mysql gem re compiled" and how would I go about doing that?

With thanks again


Nick

Schultz

unread,
Aug 24, 2006, 2:08:22 PM8/24/06
to rubyonra...@googlegroups.com
Ok sorry i thought you were on a *nix type platform where the gem's are
linked against your library's. If you are on windows then just make sure
that you are using the proper libmysql.dll from your distribution.

Normally it is located in the bin directory of your mysql install.

Also i actually perfer to put the libmysql.dll in the directory where
the ruby.exe is located. that way i don't have stuff cluttering up the
Windows system dir. Also scan your harddrive and see if there is more
instances of libmysql.dll that you might not know about that ruby is
picking up.

Nick

unread,
Aug 25, 2006, 8:52:08 AM8/25/06
to rubyonra...@googlegroups.com
Thanks for the reply but that wasn't the problem in the end. I have
successfully found what the problem was!

Having rumaged around on the web for days, I came across someone
suggesting that I install a different mysql.so in the
"C:\ruby\lib\ruby\site_ruby\1.8\i386-msvcrt" folder. I did. Nothing
changed. While trying the two different files, I was constantly changing
the names to mysql.so_old or something like that. At one point BOTH were
named _old and _new... i.e. Ruby couldn't find a SINGLE mysql.so.

And would you believe this actually worked!

It was the mysql.so file that was causing problems... Simply removing
the file made it all work again!

Very odd indeed!

Thanks for your help all the same!


Nick

Nick

unread,
Aug 25, 2006, 8:54:49 AM8/25/06
to rubyonra...@googlegroups.com
Just to add to my last post...

The major problem is that there does not appear to be ONE SINGLE
installation tutorial for Ruby/Apache/MySQL on Windows XP that actually
works. Everyone I spoke to has had to use a strange mix of numerous
different tutorials to finally get it working.

Naturally, I tried numerous different things to finally get mine working
and probaby one of them involved installing this stupid mysql.so file.

Anyway, fingers crossed, no more problems...

Schultz

unread,
Aug 25, 2006, 5:10:48 PM8/25/06
to Ruby on Rails: Talk
Nick,
I think when you deleted the mysql.so file you actually put the mysql
gem into ruby only mode. So you will have alot slower times doing stuff
with the database. instead of using a native module. (Though i am not
100% sure on this though) And i know your pain. I currently have 3
seperate environments (Linux, Windows, MacOSX) that i do development in
and Windows one has been the hardest to setup.

Rob Schultz

tkrd

unread,
Sep 4, 2006, 6:31:30 AM9/4/06
to rubyonra...@googlegroups.com

I suggest that you should confirm the version of your MySQL is NOT 5.0.24.
In my environment, MySQL 5.0.22 and MySQL 5.0.24a work fine, but the 5.0.24
does not.
The latest version was released 10 days ago...
It is quite possible that you have got the bad one unfortunately like my
colleague.


sharky wrote:
>
> I had similar problems as have been mentioned...The first operation after
> starting WEBrick or Mongrel or whatever server I was using would work
> fine, but the next would throw the undefined method 'each' on #<Mysql
> error.
>
> I think the cause was a version mismatch between the ruby bindings for
> mysql and the version of mysql server I had installed. I tried and failed
> to get everything working with MySQL Server 5.0. Today I tried the
> Instant Rails package, which includes MySQL 4.1.something, and it has
> worked fine.
>
> To anyone involved with Ruby/Rails/MySQL development, this is a pretty big
> issue. Keep us all updated if anyone gets things working like they should
> be...
>

--
View this message in context: http://www.nabble.com/undefined-method-%60each%27-for--%3CMysql%3A0x3874b20%3E-tf2099958.html#a6133190
Sent from the RubyOnRails Users forum at Nabble.com.

Ash

unread,
Oct 18, 2006, 4:19:00 PM10/18/06
to rubyonra...@googlegroups.com
Schultz wrote:
> Nick,
> I think when you deleted the mysql.so file you actually put the mysql
> gem into ruby only mode. So you will have alot slower times doing stuff
> with the database. instead of using a native module. (Though i am not
> 100% sure on this though) And i know your pain. I currently have 3
> seperate environments (Linux, Windows, MacOSX) that i do development in
> and Windows one has been the hardest to setup.
>
> Rob Schultz


hey man,

before i used to use the instant rails because it was so easy, but
recently i just installed MySQL v.5.0. with ruby 1.8 and i get this
error. and i am using webrick do you know what i need to do to make this
work ?

i would appreciate it if you could help me

thank you

Thomas Walter

unread,
Dec 10, 2006, 8:01:39 AM12/10/06
to rubyonra...@googlegroups.com
Hi Nick,

I had the same problem - and you helped me very much! Renaming mysql.so
solves all , now Rails works fine.

Thank you


thomas

John Garner

unread,
Jan 22, 2007, 12:23:47 PM1/22/07
to rubyonra...@googlegroups.com
FYI:
This problem can be caused by an a mismatch between versions of the
mySQL gem and the version of mySQL. If you are using version 2.7.3 of
the mySQL driver, make sure you upgrade your mySQL installation to
5.0.27 from 5.0.24 - that can fix the problem (worked for me...)

- John

Vlad Vlad

unread,
Oct 20, 2007, 8:43:39 PM10/20/07
to rubyonra...@googlegroups.com
This error drives me crazy! For the last 3 hours I was trying to
unsuccessfully find out what is wrong with my script, I have pinpointed
it to this:

I am running two SELECT queries like this:

require 'mysql'

dbh = Mysql.connect("localhost", "aaa", "aaa", "aaa")

#Query 1
res = dbh.query("SELECT id FROM logs WHERE id='10'");
puts "Number of rows returned: #{res.num_rows}"
res.free

#Query 2
res = dbh.query("SELECT id FROM logs WHERE id='10'");
puts "Number of rows returned: #{res.num_rows}"
res.free

And here is what I'm getting:

For the first query everything is ok: Number of rows returned:0
For the 2nd: undefined method 'num_rows' for #<Mysql:0x34eaaa18>
(NoMethodError)

For some reason the second query does not return an object of class
Mysql::Result and I have no idea why. I even tried to dbh.close and
reopen - it does not help! The INSERTS are working fine, I tried several
insert statements, and they work without a glitch.

My set-up:

OS: Windows VISTA
MySQL GEM: 2.7.3
MySQL: 5.1.22
Ruby: 1.8.6

Your help will be extremely appreciated!

Vlad Vlad

unread,
Oct 21, 2007, 7:12:24 AM10/21/07
to rubyonra...@googlegroups.com
Vlad Vlad wrote:
> For some reason the second query does not return an object of class
> Mysql::Result and I have no idea why. I even tried to dbh.close and
> reopen - it does not help! The INSERTS are working fine, I tried several
> insert statements, and they work without a glitch.

I've managed to go around it, although I do not understand what caused
an issue. Any way, when I use the block notation, it works fine:

dbh.query("SELECT id FROM logs WHERE id='10'") { |res| puts "Number of
rows returned: #{res.num_rows}" }

Hope it helps someone, and if you can explain what causes that
behaviour, will be very good.

Reply all
Reply to author
Forward
0 new messages