# Segmentation Fault when using MySql from Ruby - please help

**URL:** <https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698>\
**Category:** Ruby\
**Created:** [May 21, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698 "2007-05-21T18:28:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 21, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698/1 "2007-05-21T18:28:31Z")

</div>

Hello,

I have installed the “mysql” gem for Ruby running on Windows.  
The version of mysql is 2.7.3, the version of Ruby is 1.8.5.

When I run the following program:

require ‘mysql’  
mysql=Mysql.init  
Mysql.real\_connect(‘localhost’,‘gast’,‘gast’,‘test’)  
mysql.query(‘select count(\*) from t1’)

I get a segmentation fault at the last statement:

# ========================================================================

ex1.rb:5: [BUG] Segmentation fault  
ruby 1.8.5 (2006-12-25) [i386-mswin32]

# This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information.

=======

What am I doing wrong here? Usually I would assume that a SEGV means  
there is a bug in the Ruby implementation; but since my code is  
so simple and common (simply doing a SQL query), I suspect that it  
is in my code.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 21, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698/2 "2007-05-21T18:45:33Z")

</div>

Not sure if this is your segfault… But you’re using these in a way I  
haven’t seen. I assign the connect call to an obj and query that…

con\_obj = Mysql.real\_connect blah  
res\_set = con\_obj.query(blah)

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 21, 2007, 8:47pm UTC](https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698/3 "2007-05-21T20:47:03Z")

</div>

Also make sure that libmysql.dll is in your PATH and available to Ruby.

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 22, 2007, 10:39am UTC](https://www.ruby-forum.com/t/segmentation-fault-when-using-mysql-from-ruby-please-help/104698/4 "2007-05-22T10:39:24Z")

</div>

> Not sure if this is your segfault… But you’re using these  
> in a way I haven’t seen. I assign the connect call to an  
> obj and query that…
> 
> con\_obj = Mysql.real\_connect blah  
> res\_set = con\_obj.query(blah)

Indeed, that was it - I used the library in a strange way; and  
as we all know: Garbage In - Garbage Out … 😉

Thanks a lot,

Ronald
