0

迁移 Mysql 和 Rails 时遇到了一些麻烦

信息 - - - - - - - - - - - - -

MySQL Server 5.5(我试过 MySQL Server 5.1,但没用)
Ruby 1.9.3-p429
Rails 3.2


我已经用过

“gem 安装 mysql2 -v 0.2.6”
“gem 安装 mysql”

并添加到 gemfile

gem 'mysql'
gem 'mysql2','>=0.2.6'

当我将数据库迁移到 MySQL
类型“rake db:migrate”
并得到错误的文件描述符时出现错误

C:\Sites\demo> rake db:migrate
rake 中止!
错误的文件描述符
任务:TOP => db:migrate
(通过使用 --trace 运行任务查看完整跟踪)

细节

C:\Sites\demo> rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
rake aborted!
Bad file descriptor
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `query'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:312:in `execute'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:629:in `configure_
connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:169:in `initialize
'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mi
ngw32/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_conn
ection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_co
nnection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checko
ut_new_connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquir
e_connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block
in checkout'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchr
onize'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checko
ut'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block
in connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchr
onize'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connec
tion'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrie
ve_connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_handling.rb:79:in `retrieve_connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/connection_handling.rb:53:in `connection'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/migration.rb:863:in `initialize'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/migration.rb:764:in `new'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/migration.rb:764:in `up'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/migration.rb:742:in `migrate'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/
lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (requi
red)>'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:236:in `call'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:236:in `block in execute'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:231:in `each'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:231:in `execute'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:175:in `block in invoke_with_call_chain'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchr
onize'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:168:in `invoke_with_call_chain'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/task.rb:161:in `invoke'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:149:in `invoke_task'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:106:in `block (2 levels) in top_level'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:106:in `each'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:106:in `block in top_level'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:115:in `run_with_threads'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:100:in `top_level'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:78:in `block in run'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:165:in `standard_exception_handling'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/lib/rak
e/application.rb:75:in `run'
D:/AppServ/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rake-10.1.0/bin/rak
e:33:in `<top (required)>'
D:/AppServ/RailsInstaller/Ruby1.9.3/bin/rake:23:in `load'
D:/AppServ/RailsInstaller/Ruby1.9.3/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate

我修改了“database.yml”

development:
  adapter: mysql2
  encoding: utf8
  database: demo_development
  host: 127.0.0.1
  username: 'root'
  password: '1234'
  port: 3306

test:
  adapter: mysql2
  encoding: utf8
  database: demo_test
  host: 127.0.0.1
  username: 'root'
  password: '1234'
  port: 3306

production:
  adapter: mysql2
  encoding: utf8
  database: demo_production
  host: 127.0.0.1
  username: 'root'
  password: '1234'

希望有人可以帮助我
我的股票好几天
谢谢!

4

1 回答 1

0

尝试从 gemfile 中删除 'mysql' gem,只需要 'mysql2',删除后执行捆绑安装。

来自 github 上 mysql 的文档

要使用 Active Record 驱动程序(带或不带 rails),您需要做的就是安装此 gem 并将 database.yml 中的适配器设置为“mysql2”。那很容易吧?:)

注意:从 0.3.0 和 Active Record 3.1 开始,Active Record 适配器已从这个 gem 中提取出来并进入 Active Record 本身。如果您需要在 Rails 版本 < 3.1 中使用 mysql2,请确保在 Gemfile 中指定 gem "mysql2", "~> 0.2.7"

也参考this在windows中安装问题

Rails安装windows 7坏文件描述符mysql2

于 2013-07-29T10:04:38.540 回答