【问题标题】:MySQL/Ruby on WindowsWindows 上的 MySQL/Ruby
【发布时间】:2010-11-04 13:59:59
【问题描述】:

我正在尝试在 Windows XP 上将 Rails 2.3.2 与 MySQL 5.0 一起使用,但没有成功。
我已经安装了 MySQL 并且能够运行它、添加表等。
在 ruby​​ 中,require 'mysql' 语句通过了,但它到达了第一个动作,然后我得到了

> 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'

知道我做错了什么吗?

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)

【问题讨论】:

  • 你的路径是什么样的?可以从命令行调用irb吗?
  • 是的,我的路径中有 ruby​​/bin 和 mysql/bin
  • Rails 3.2.3 尚未发布。可能你在谈论 Rails 2.3.2... ;)

标签: mysql windows ruby


【解决方案1】:

您不会收到任何其他错误,例如缺少 dll 文件等吗?通常使用数据库连接器,您必须将相应的 dll 文件(如 mysql.dll)添加到 PATH(或 ruby​​s“bin”目录中),这样 ruby​​ 才能找到它们。

【讨论】:

  • 我阅读了几个关于将 mysql.dll 放在 ruby​​/bin 中的地方,但这并没有什么不同。
  • 您必须拥有与编译 mysql gem 的(几乎)相同版本的 mysql,或者自己重新编译 gem。 (两者都不容易)。或者您可能想切换到 SQLite 或 Postgres,它们在 Windows 上的问题通常较少。
【解决方案2】:

如果您不部署到 Windows,并且您的开发数据是合理的(SQLite installation on Windows is pretty easy - 您只需要使用旧版本的 gem,因为最新版本已损坏。

Postgres 是另一回事。如果 SQLite 可以工作,我不会使用它。与 SQLite 或 MySQL 不同,它在使用 LIKE 时默认执行区分大小写的搜索。如果您确实使用它,请检查您的插件是否有 LIKE 查询。

【讨论】:

  • 部署在 Linux 上。 DB 将包含至少一个包含 10-15K 记录的表。如果就 SQL 而言没有区别,那么在 SQLite 上进行开发将是最好的解决方案。
猜你喜欢
  • 2012-11-20
  • 2021-11-13
  • 2015-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-29
  • 2011-04-21
  • 1970-01-01
相关资源
最近更新 更多