Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 'mysql' gem segmentation fault

Tags:

mysql

ruby

I'm using Ruby 1.9.3 and I'm experiencing this strange problem with the 'mysql' Ruby gem going on segmentation fault exactly after the execution of 20 queries.

This is the code which executes the query:

def load
        dbh = Mysql::new($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME)
        begin
            res = dbh.query("SELECT word, type FROM words WHERE word = '#{dbh.escape_string(word)}';")
        rescue Mysql::Error => e
            puts "Error occurred during SQL query"
        end
        res.each do |row|
            @word = row[0]
            @type = row[1]
        end
        dbh.close if dbh
    end

This code gets called everytime the user enters a word, for the first 20 words the query works right and goes on segfault on the 21st no matter what I put in there.

I'm on Windows, using Ruby 1.9.3p0 and ruby 'mysql' gem version 2.8.1, with MySQL 5.5.16. I've already checked that the libmysql.dll file I copied into the Ruby bin folder is the same version of the MySQL I have installed.

Do you have any other hint about what could be going wrong?

like image 574
The Coding Monk Avatar asked May 01 '26 02:05

The Coding Monk


1 Answers

Here's the solution for anyone who comes across this in the future:

It seems the reason is that this version of mysql gem does not work with MySQL 5.1 lib. [...] Download MySQL 5.0 noinstall version mysql-noinstall-5.0.89-win32.zip from http://dev.mysql.com/downloads/mysql/5.0.html. Extract libmysql.dll and copy it to C:\Ruby\bin. Then, the problem is solved. I am still running MySQL 5.1. But Ruby uses this MySQL 5.0 version dll.

Source: http://fuyun.org/2010/01/ruby-mysql-adapter-on-windows/

like image 99
David Avatar answered May 02 '26 16:05

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!