user429400
user429400

Reputation: 3325

ruby: connection to mysql closes after a single query

I'm writing a ruby script that has several select queries. At the beginning of the script I'm initializing a new database connection:

db = Mysql.new 'localhost', 'root', 'pass', 'mydb', 3308

The first select query succeeds, but when it gets to second one the following error occurs:

in `query': query: not connected (Mysql::Error)

I can solve this by copying the connection initialization line before each query, but I really don't think that this is the right solution here.

Thanks, Li

Adding my full script (I'm new at this, so sorry for the miserable style): (Replaced the original script with a much more simple repro): In the following code, if I comment out the "SELECT" query and leave only the "INSERT INTO" queries, everything works great. But if I try to run the code as is, I get the above error.

#!/usr/local/bin/ruby -w 

require "mysql"

dbname = "sample_db"

m = Mysql.new 'localhost', 'root', 'passw', 'sample_db', 3306

m.select_db(dbname)

m.query("CREATE TABLE words         
     (          
       german varchar(30),          
       english varchar(30),          
       french varchar(30)         
     )"        
   )

m.query("INSERT INTO words VALUES('Adler', 'eagle', 'aigle')")

results = m.query("SELECT german, english FROM words")

m.query("INSERT INTO words VALUES('Haus', 'house', 'maison')")

m.close

Upvotes: 0

Views: 455

Answers (1)

user429400
user429400

Reputation: 3325

Found the answer in:

http://halyph.blogspot.com/2009/08/rails-23-migration-issues-with-mysql_26.html

seems that this is a common issue, I just had to replace libmysql.dll with: http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

and then restart my mysql service. Note that I already replace my dll (after having installation issues) but only the dll from rubyforge seem to have solved this issue

Note that another symptom of this issue is sporadic segmentation faults. These also disappeared after replacing the dll

Upvotes: 1

Related Questions