views:

242

answers:

2

I am trying to use Rails 2.3.2 with MySQL 5.0 on Windows XP with no luck.
I have installed MySQL and am able to run it, add tables etc.
In ruby, the require 'mysql' statement passes but onde it reached the first action then I get

> C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:7:in `define_all_hashes_method!': Mysql not loaded (RuntimeError)
        from C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:71:in `mysql_connection'
        from C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
        from C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
        from C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
        from C:/Development/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'

Any idea to what I am doing wrong?

require 'rubygems'
require 'activerecord'
require 'mysql'

ActiveRecord::Base.establish_connection(
    :adapter => "mysql",
    :host => "127.0.0.1",
    :database => "ruby"
)


class Student < ActiveRecord::Base
end
Student.find(:all)
A: 

Don't you get any other errors, like missing dll files, etc.? Usually with database connectors you have to add the appripriate dll files (like mysql.dll) to the PATH (or in rubys "bin" directory), so ruby can find them.

SztupY
I read several places about placing the mysql.dll in ruby/bin but this did not make a difference.
lk
You have to have the (almost) same version of mysql as the mysql gem was compiled with, or recompile the gem yourselves. (Neither one is easy). Or you might want to switch to SQLite or Postgres, they have less problems on windows usually.
SztupY
A: 

If you're not deploying to Windows, and your development data is reasonable (<10k rows/table) I'd switch to SQLite. It's sufficiently generic that you should be able to painlessly deploy on MySQL. SQLite installation on Windows is pretty easy - you just have to use an older version of the gem as the newest is broken.

Postgres is another story. I wouldn't use it if SQLite will work. It does case-sensitive searches by default when using LIKE, unlike SQLite or MySQL. If you do use it, check your plugins for LIKE queries.

Sarah Mei
Deployment is on Linux.DB will contain at least one table with 10-15K records.If there is no difference as far as SQL is concerned, then doing development on SQLite would be the best solution.
lk