简体   繁体   中英

Ruby 'mysql' gem segmentation fault

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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM