Ruby on rails 连接问题

2021-12-23 00:00:00 ruby-on-rails mysql activerecord

我有一个 Ruby on Rails 项目,我正在托管服务器上开发该项目,但已决定在我的本地 Windows 机器上工作.

I have a Ruby on Rails project that I was developing on a hosted server but have decided to work on my local windows machine with.

一开始我想我会确保我可以从旧项目中取出我的模型并将它们放在一个新项目中,然后在控制台中查询它们.这失败了.

To get started I thought I'd make sure that I could just take my models from the old project and put them in a new project then query them in the console. This fails.

编辑以反映更准确的问题:rails 为查询我的模型而建立的连接只能运行一个查询,然后为所有后续查询提供未连接​​"异常.有人知道这是怎么回事吗?我检查了我的配置,很多.如果 mysql 服务器上有一些我不知道的设置,我愿意查看.

Edit to reflect more accurate problem: The connection that rails builds to query my models can run only one query then gives the "Not connected" exception for all subsequent queries. Anybody know what's going on? I've checked my configuration, a lot. If there's some setting on mysql server that I don't know about I'd be willing to look at that.

堆栈跟踪:

Price.find(1)
ActiveRecord::StatementInvalid: Mysql::Error: query: not connected: SHOW FIELDS FROM `prices`
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:466:in `columns'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1271:in `columns'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1279:in `columns_hash'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1578:in `find_one'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1569:in `find_from_ids'
        from c:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:616:in `find'
        from (irb):2

我已经确认我的 MySQL 数据库正在接受连接并且具有我期望的数据和结构.我已经仔细检查了我的连接等.有人能解释一下吗?

I've verified that my MySQL database is accepting connections and has the data and structure I expect. I've double checked my connections, etc. Can anyone shed some light?

推荐答案

我在 aptana 论坛.

那里说 MySQL 5.1 客户端库不能很好地与 Rails 2.2 配合使用他们提供的解决方案很简单:下载一个旧的 MySQL 客户端库 (libmySQL.dll) 并将其复制到您的 Rubyin 文件夹.

There it says that the MySQL 5.1 client library doesn't play well with Rails 2.2 The solution they offer is simple: download an older MySQL client library (libmySQL.dll) and copy it to your Rubyin folder.

这对我有用(Windows XP、Ruby 1.8.6、Rails 2.3.3、mysql 5.1.33)

This worked for me (Windows XP, Ruby 1.8.6, Rails 2.3.3, mysql 5.1.33)

相关文章