迁移Mysql和Rails时遇到了一些麻烦
信息--------------------------
MySQL Server 5.5(我曾尝试过MySQL Server 5.1,但没有工作)
Ruby 1.9.3-p429
Rails 3.2
我已经使用
了“gem install mysql2 -v 0.2.6”
“gem install mysql”
并添加到gemfile
gem'mysql'
gem'mysql2','> = 0.2.6'
我将数据库迁移到MySQL时遇到错误
输入“rake db:migrate”
得到错误的文件描述符
C:\网站\演示> rake db:migrate 耙子流产!
文件描述符错误
任务:TOP => DB:迁移
(通过使用--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'
希望有人可以帮助我
我好几天了
谢谢!
答案 0 :(得分:0)
尝试从gemfile中删除'mysql'gem,只需要'mysql2',删除后再进行bundle install。
来自github上的mysql文档
要使用Active Record驱动程序(带或不带导轨),所有人 应该做的是安装这个gem并设置适配器 你的database.yml到“mysql2”。这很容易吗? :)
注意:从0.3.0开始,和Active Record 3.1 - Active Record适配器 已经退出这个宝石并进入Active Record本身。如果你 需要使用带有Rails版本的mysql2&lt; 3.1确保并指定gem 你的Gemfile中的“mysql2”,“〜&gt; 0.2.7”
也请参考这个在Windows中安装问题