Mysql adapter ActiveRecord in Ruby throwing: 'Packets out of order'

后端 未结 1 568
隐瞒了意图╮
隐瞒了意图╮ 2021-01-25 08:21

Ruby version: 1.9.1 Mysql version: 5.0

code written was:


    require \"rubygems\"
    require \"active_record\"
    puts \"1\"
    class Source <          


        
相关标签:
1条回答
  • Finally, after putting all my efforts with MySql and Postgresql, I am able to make successful connection with MySql.
    Working set involves:
    Ruby Version: 1.87
    MySql Version: 5.5
    To work with ActiveRecord, one need to have the adapter installed. On command prompt, write:
    gem install mysql2.

    Code to build successful connection of MySql database with Ruby under the layer of 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
    

    Note: Adapter used is mysql2 and not mysql

    0 讨论(0)
提交回复
热议问题