当前位置: 代码迷 >> Ruby/Rails >> rake db:migrate为什么出现Mysql:Error: query: not connected异常
  详细解决方案

rake db:migrate为什么出现Mysql:Error: query: not connected异常

热度:67   发布时间:2016-05-06 04:23:28.0
rake db:migrate为什么出现Mysql::Error: query: not connected错误
网上也没有搜到相关问题,请高手帮忙
trace如下:
C:\Users\Administrator\Documents\NetBeansProjects\MyDigger>rake db:migrate --trace
(in C:/Users/Administrator/Documents/NetBeansProjects/MyDigger)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:320:in `execute'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `create_table'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/mysql_adapter.rb:473:in `create_table'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/connection_adapters/abstract/schema_statements.rb:320:in `initialize_schema_migrations_table'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/migration.rb:436:in `initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/migration.rb:400:in `new'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/migration.rb:400:in `up'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/migration.rb:383:in `migrate'
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/tasks/databases.rake:116
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
C:/Ruby/bin/rake:19:in `load'
C:/Ruby/bin/rake:19

------解决方案--------------------
错误提示数据库没有连接上。

1、mysql数据库开了吗
2、database.yml 文件打开看看,是不是数据的配置没有配置好
------解决方案--------------------
根据这个提示
CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB 


去你的数据库看下是不是这个表没有建立或者有问题。建议你删除这个表后再migrate
------解决方案--------------------
如果是初学,建议用sqlite3作为你的development DataBase
------解决方案--------------------
这是因为新版mysql的客户端连接库对rails 2.2的支持不够好导致的,解决办法是使用旧版的客户端连接库,也就是把旧版mysql的libmySQL.dll文件(该文件在mysql安装目录的bin文件夹下面)复制到ruby目录下的bin文件夹中就可以解决这个问题了。

外国论坛上有人使用这个配置可以正常解决:Ruby 1.8.6, Rails 2.3.3, mysql 5.1.33
我的配置是:Ruby 1.8.6, Rails 2.3.2, mysql 5.0.67
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Sun Feb 19 19:51:34 CST 2017
  • 最近登录:Sun Feb 19 19:51:34 CST 2017
  • 最近登录:Sun Feb 19 19:51:34 CST 2017
  • 最近登录:Sun Feb 19 19:51:34 CST 2017
  • 最近登录:Sun Feb 19 19:51:34 CST 2017