# Ruby on Windows with mysql and net

**URL:** <https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920>\
**Category:** Ruby\
**Created:** [January 23, 2008, 1:35pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920 "2008-01-23T13:35:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 1:35pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/1 "2008-01-23T13:35:36Z")

</div>

Hello all,

I’m a new Ruby user, so pardon me if this is a silly question, but I’ve  
done  
some googling and not found any answers so far. Apologies in advance if  
this  
post is a little long, but I thought it might help to list what I’ve  
done so  
far.

I’ve downloaded Ruby 1.8.6 One-Click Installer, and got Ruby up and  
running  
on my Win XP box. Then I used RubyGems to obtain v 2.7.3 of the MySQL  
API.

The idea is to connect to MySQL running on Ubuntu Server on another box  
on  
my LAN - that part of the equation seems to work ok, in that I can  
connect  
to MySQL from the Windows box using MySQL Administrator etc. The data to  
be  
retrieved is login details (server, username, password) for several POP3  
mail boxes - I eventually want Ruby to get details for each box from the  
database, connect to the mailbox, download mail and process it etc…

However, when I tried to query the database via Ruby I got a  
Segmentation  
Fault. After much googling I found I needed libmySQL.dll in my path, and  
tried various versions of the file (including the one that came with  
MySQL  
Administrator, and the one in MySQL 5.1.22), before getting things to  
work  
with the version from MySQL 5.0.45.

Great, Ruby can now retrieve a result set from the database containing  
login  
details for the two POP3 boxes currently stored there. Also, by using  
the  
demo code in the docs for net/pop and hard coding the login details for  
any  
given mailbox, I can connect to the mail server.

But, when I merge the code together, things go slightly wrong. Ruby  
retrieves the details from the database and connects to the mail servers  
correctly, but, when the program ends, I get:

Error in my\_thread\_global\_end(): 1 threads didn’t exit

> Exit code: 0

The code I’m using is below. It’s messy and long winded, but it IS my  
first  
attempt ever at writing Ruby code - I like what I see so far, and I WILL  
get  
better at it 🙂

To keep things shorter than they woud otherwise be, I’ve removed the  
code  
between pop.start and pop.finish, since the error happens whether it’s  
present or not.

Any suggetions would be very much appreciated!

TIA

Simon.

#!/usr/bin/ruby -w

require ‘net/pop’

require “mysql”

begin  
# connect to the MySQL server  
dbh = Mysql.real\_connect(“xxx.xxx.xxx.xxx”, “username”, “password”,  
“database”)  
# get get email account details  
res = dbh.query(“SELECT name, server, user\_name, password FROM  
pop\_boxes”)  
if res.nil? then  
puts “Statement has no result set”  
else  
puts “Statement has a result set”  
while row = res.fetch\_hash do  
printf “%s\n”, row[“name”]  
pop = Net::POP3.new(row[“server”])  
pop.start(row[“user\_name”], row[“password”])

```
    pop.finish
    printf "%s, %s,%s, %s\n", row["name"], row["server"],

```

row[“user\_name”], row[“password”]  
end  
end  
puts “Number of rows returned: #{res.num\_rows}”  
res.free  
rescue Mysql::Error =\> e  
puts “Error code: #{e.errno}”  
puts “Error message: #{e.error}”  
puts “Error SQLSTATE: #{e.sqlstate}” if e.respond\_to?(“sqlstate”)  
ensure  
# disconnect from server  
dbh.close if dbh  
end

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/2 "2008-01-23T15:15:25Z")

</div>

On 23 ene, 10:31, “Simon Jones” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello all,
> 
> I’m a new Ruby user, so pardon me if this is a silly question, but I’ve done  
> some googling and not found any answers so far. Apologies in advance if this  
> post is a little long, but I thought it might help to list what I’ve done so  
> far.

No problem, I’m used to write long posts 🙂

> However, when I tried to query the database via Ruby I got a Segmentation  
> Fault. After much googling I found I needed libmySQL.dll in my path, and  
> tried various versions of the file (including the one that came with MySQL  
> Administrator, and the one in MySQL 5.1.22), before getting things to work  
> with the version from MySQL 5.0.45.

The pre-build gem of mysql 2.7.3 is build for 5.0.x version of MySQL,  
anything above that will generate a segfault due changes in the API/  
exported symbols of libmySQL.dll

> > Exit code: 0

That is correct, nothing wrong with your code.

Is a known problem of MySQL 5.0.x, and still wasn’t solved in latest  
version of it:

[http://bugs.mysql.com/bug.php?id=25621](http://bugs.mysql.com/bug.php?id=25621)

The problem is the lack of a newer version of the installers (official  
ones) for 5.0.x and the issue I mention above about pre-build gem.

> The code I’m using is below. It’s messy and long winded, but it IS my first  
> attempt ever at writing Ruby code - I like what I see so far, and I WILL get  
> better at it 🙂

You code looks good. The issue also happens on other platforms, not  
just Windows 😉

> Any suggetions would be very much appreciated!

Just ignore the error for the time being? 🙂  
I’m doing that on a daily basis, so maybe you can too 😉

Regards,

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 5:15pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/3 "2008-01-23T17:15:49Z")

</div>

“Luis L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> On 23 ene, 10:31, “Simon Jones” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> Just ignore the error for the time being? 🙂  
> I’m doing that on a daily basis, so maybe you can too 😉

Thanks for that, Luis! I’m happy to ignore it now that I know there’s  
nothing I can do about it:-)

Have you noticed any unfortunate side effects from the issue? Any memory  
leaks or anything, either with the client code or at the MySQL end? Just  
curious to know if ignoring is going to catch up with me eventually!

Simon.

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/4 "2008-01-23T19:46:56Z")

</div>

Luis L. wrote:

> The pre-build gem of mysql 2.7.3 is build for 5.0.x version of MySQL,  
> anything above that will generate a segfault due changes in the API/  
> exported symbols of libmySQL.dll
> 
> > > Exit code: 0
> 
> That is correct, nothing wrong with your code.
> 
> Is a known problem of MySQL 5.0.x, and still wasn’t solved in latest  
> version of it:
> 
> [http://bugs.mysql.com/bug.php?id=25621](http://bugs.mysql.com/bug.php?id=25621)
> 
> The problem is the lack of a newer version of the installers (official  
> ones) for 5.0.x and the issue I mention above about pre-build gem.
> 
> > The code I’m using is below. It’s messy and long winded, but it IS my first  
> > attempt ever at writing Ruby code - I like what I see so far, and I WILL get  
> > better at it 🙂
> 
> You code looks good. The issue also happens on other platforms, not  
> just Windows 😉
> 
> > Any suggetions would be very much appreciated!
> 
> Just ignore the error for the time being? 🙂  
> I’m doing that on a daily basis, so maybe you can too 😉
> 
> Regards,

Is there anything I can do with the pre-built gem that would help? I  
stopped using MySQL personally over a year ago, but I have heard very  
few complaints about the pre-built gem since then. If I need to make a  
fresh build in one form or another, I can try.

Since I don’t use MySQL anymore, anyone who wishes to take over the gem  
project could do so. Ping me off-list, my gmail account is ‘kevwil’.

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 11:42pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/5 "2008-01-23T23:42:08Z")

</div>

On 23 ene, 14:07, “Simon Jones” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nothing I can do about it:-)
> 
> Have you noticed any unfortunate side effects from the issue? Any memory  
> leaks or anything, either with the client code or at the MySQL end? Just  
> curious to know if ignoring is going to catch up with me eventually!

In case you’re using mongrel\_service (for serving Rails applications)  
you will find that sometimes the service fails at stopping process,  
mostly due this.

libmysql.dll takes 2 or 3 seconds to release the locking on some  
threads until it kill them. That isn’t good, but so far, no data  
corruption or any other issue server or client side besides the one I  
mention from mongrel\_service.

Regards,

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 24, 2008, 8:55am UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/6 "2008-01-24T08:55:32Z")

</div>

“Luis L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in message  
news:removed\_email\_address@domain.invalid…

> libmysql.dll takes 2 or 3 seconds to release the locking on some  
> threads until it kill them. That isn’t good, but so far, no data  
> corruption or any other issue server or client side besides the one I  
> mention from mongrel\_service.

Thanks again, Luis. I’m not using Rails, so ignoring the problem sounds  
good  
to me 🙂

Simon.

---

<div class="post-metadata">

**Author:** ![Simon\_Jones](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Simon\_Jones](https://www.ruby-forum.com/u/Simon_Jones)\
**Post date:** [January 23, 2008, 11:46pm UTC](https://www.ruby-forum.com/t/ruby-on-windows-with-mysql-and-net/126920/7 "2008-01-23T23:46:17Z")

</div>

On 23 ene, 16:46, Kevin W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > version of it:  
> > You code looks good. The issue also happens on other platforms, not  
> > stopped using MySQL personally over a year ago, but I have heard very  
> > few complaints about the pre-built gem since then. If I need to make a  
> > fresh build in one form or another, I can try.

Thank you Kevin for answering.

I’ve tried rebuild the gem with MySQL 5.1.x, but then it stops working  
with MySQL 5.0.x, doing segfaults (the inverse scenario previously  
described).

> Since I don’t use MySQL anymore, anyone who wishes to take over the gem  
> project could do so. Ping me off-list, my gmail account is ‘kevwil’.

The thing is 5.1.x is “Release Candidate”, and maintain compatibility  
with boths gems seems overkill, mostly that you aren’t around  
anymore 😉

I’ll try to catch you later this weekend and maybe we can both come to  
a good solution for it.

Regards,
