Adaptador Mysql ActiveRecord en lanzar Ruby: ‘Paquetes fuera de servicio’

Versión Ruby: 1.9.1 Versión Mysql: 5.0

El código escrito fue:

require "rubygems" require "active_record" puts "1" class Source  "mysql", :host => "localhost", :username => "root", :password => "root@123", :database => "TrafficTracker" ) end puts "3" traffic_source = Source.find(1) puts "4" puts traffic_source.source_name 

El código anterior imprime hasta 3 y se rompe en Source.find (1) con error:

1 2 3 C: /Ruby/lib/ruby/1.9.1/mysql.rb: 1019: en read': Packets out of order: 0 (RuntimeError)
from C:/Ruby/lib/ruby/1.9.1/mysql.rb:444:in
read': Packets out of order: 0 (RuntimeError)
from C:/Ruby/lib/ruby/1.9.1/mysql.rb:444:in
read': Packets out of order: 0 (RuntimeError)
from C:/Ruby/lib/ruby/1.9.1/mysql.rb:444:in
lectura ‘de C: /Ruby/lib/ruby/1.9.1/mysql.rb: 110: en real_connect' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:600:in connect ‘desde C: /Ruby/lib/ruby/gems/1.9.1 /gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:164:in initialize' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb:36:in new ‘from C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/mysql_adapter.rb: 36: in mysql_connection' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:228:in new_connection’ de C: / Ruby / lib /ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in checkout_new_connection' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in checkout_new_connection' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in bloque (2 niveles) en c heckout ‘desde C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd /connection_adapters/abstract/connection_pool.rb:186:in loop' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd/connection_adapters/abstract/connection_pool.rb:186:in block in checkout ‘de C: /Ruby/lib/ruby/1.9.1/monitor.rb: 201: in mon_synchronize' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd/connection_adapters/abstract/connection_pool.rb:185:in checkout ‘de C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd / connection_adapters / abstract / connection_pool.rb: 93: in connection' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd/connection_adapters/abstract/connection_pool.rb:316:in retrieve_connection ‘from C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd / connection_adapters / abstract / connection_specificati on.rb: 97: in retrieve_conn ection' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd/connection_adapters/abstract/connection_specification.rb:89:in connection ‘desde C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_reco rd / base.rb: 679: en las columns' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/persistence.rb:284:in attributes_from_column_definition ‘de C: /Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3 /lib/active_record/locking/optimistic.rb:62:in attributes_from_column_definition' from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/active_record/base.rb:1394:in initialize ‘desde C: /WorkspaceGunjan/TrafficTracker/TrafficTracker/TestProject/RubyPrograms/RubyPrograms/AccessTrafficTracker.rb: 22: en la categoría de new' from C:/WorkspaceGunjan/TrafficTracker/TrafficTracker/TestProject/RubyPrograms/RubyPrograms/AccessTrafficTracker.rb:22:in ‘C: \ WorkspaceGunjan \ TrafficTracker \ TrafficTracker \ TestProject \ RubyPrograms \ RubyPrograms> C: \ WorkspaceGunjan \ TrafficTracker \ TrafficTracker \ TestProject \ RubyPrograms \ RubyPrograms> C: \ WorkspaceGunjan \ TrafficTracker \ TrafficTracker \ TestProject \ RubyPrograms \ RubyPrograms>

después de analizar más, encontré un problema con mysql.rb en \ Ruby \ lib \ ruby ​​\ 1.9.1 El problema de creación del método es:

 def read() buf = [] len = nil @sock.sync = false while len == nil or len == MAX_PACKET_LENGTH do a = @sock.read(4) len = a[0]+a[1]*256+a[2]*256*256 pkt_nr = a[3] if @pkt_nr != pkt_nr then raise "Packets out of order: #{@pkt_nr}#{pkt_nr}" #Exception raised at line number 1019 end @pkt_nr = @pkt_nr + 1 & 0xff buf << @sock.read(len) end @sock.sync = true buf.join end 

Finalmente, después de poner todos mis esfuerzos con MySql y Postgresql, puedo hacer una conexión exitosa con MySql.
Conjunto de trabajo implica:
Versión Rubí: 1.87
Versión de MySql: 5.5
Para trabajar con ActiveRecord, uno necesita tener el adaptador instalado. En el símbolo del sistema, escriba:
gem instalar mysql2.

Código para construir una conexión exitosa de la base de datos MySql con Ruby bajo la capa de ActiveRecord:

 require "rubygems" require "active_record" class Source < ActiveRecord::Base set_table_name "sources" ActiveRecord::Base.establish_connection( :adapter => "mysql2" , :host => "localhost", :username => "test", :password => "test", :port => 3306, :database => "TestDB", :socket => "mysql" ) end source = Source.find(:first, :conditions => [ "source_id = ?", 2 ]) puts source.source_name 

Nota: el adaptador utilizado es mysql2 y no mysql