2012-03-14 49 views
19

我们最近在Ubuntu 10.04LTS服务器上从MySQL 5.1.41升级到5.1.61。我们有一个古老的回报率的Web应用程序,现在给人一种不好的握手错误:Ruby on Rails MySQL#08S01Bad握手 - 降级MySQL?

Mysql::Error in MainController#index 

#08S01Bad handshake 

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/vendor/mysql.rb:523:in `read' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/vendor/mysql.rb:153:in `real_connect' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:389:in `connect' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:152:in `initialize' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `new' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:82:in `mysql_connection' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `send' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:262:in `connection_without_query_cache=' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/query_cache.rb:54:in `connection=' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:230:in `retrieve_connection' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:763:in `columns' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:2060:in `attributes_from_column_definition_without_lock' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/locking/optimistic.rb:45:in `attributes_from_column_definition' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1502:in `initialize_without_callbacks' 
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:225:in `initialize' 
#{RAILS_ROOT}/app/controllers/application.rb:48:in `new' 
#{RAILS_ROOT}/app/controllers/application.rb:48:in `log_info' 
/usr/local/bin/mongrel_rails:19:in `load' 
/usr/local/bin/mongrel_rails:19 

我用Google搜索周围,无意中发现了这http://bugs.ruby-lang.org/issues/5017告诉我,这是一个Ruby的MySQL扩展错误。我们没有使用MySQL gem。我们的Web应用程序非常古老而且易碎(Ruby v1.8.7,Rails v1.2.3,Mongrel 1.1.5)。我们正在用Django重写代替它,所以我们只需要在接下来的几周内实现这个功能,直到我们将其替换为新的站点。

我们怎么能通过这个错误?我认为降级到MySQL 5.1.41是处理这个问题的最佳方式,然后当我们在几周内开始使用新网站时,我们可以重新升级到5.1.61。但是,我遇到了降级mysql的问题。这是我使用的命令:

sudo aptitude install mysql-server-5.1=5.1.41-3ubuntu12.10

然而,这告诉我Unable to find a version "5.1.41-3ubuntu12.10" for the package "mysql-server-5.1"。我也试过sudo aptitude install mysql-server-5.1=5.1.41,但那也没用。我如何才能安装正确版本的MySQL?

+1

*我在想,降级到MySQL 5.1.41是处理这个*最好的方式,如果你的数据库连接代码是集中,也许在你的链接中使用解决方法? *避免此问题的解决方法是在建立连接时不设置数据库。* – 2012-03-14 21:24:06

+1

也许这只是我并不熟悉RoR,但我不知道如何执行此操作。数据库连接设置在'config/database.yml'中,我不知道如何让站点与MySQL接口,而不必在该文件中指定数据库名称。我没有尝试注释数据库名称,但我得到一个新的错误:'没有指定数据库。缺少参数:database.' – Geoff 2012-03-14 21:31:31

+1

我刚刚遇到同样的问题,从.49升级到.61。在Debian Squeeze上,降级为:'sudo aptitude install mysql-server-5.1 = 5.1.49-3 mysql-client-5.1 = 5.1.49-3 mysql-common = 5.1.49-3 mysql-server-core-5.1 = 5.1.49-3 libmysqlclient16 = 5.1.49-3'。 – gsreynolds 2012-04-02 08:34:12

回答

2

我修好了!降级MySQL的伎俩。一旦Django网站上线,我们将重新升级到5.1.61。这里是降级的MySQL命令:

sudo aptitude install mysql-server-5.1=5.1.41-3ubuntu12 mysql-client-5.1=5.1.41-3ubuntu12 mysql-server-core-5.1=5.1.41-3ubuntu12

我用apt-cache得到确切的版本。

2

我也有同样的问题。请加:

config.gem 'mysql', :version => '2.7' 

然后运行rake gems:install

23

而不是降级MySQL gem,可以修复数据库名称参数以修复"bad handshake"问题。

我发现这个:https://github.com/rubygems/rubygems/issues/423它工作的很好。

而是在real_connect做一个黑客有可能加入"\0"config/database.yml

production: 
    database: "itsalive_production\0" 
    adapter: mysql 
    host: localhost 
    encoding: UTF8 
    ... 

编辑
如果您使用\0解决方案在数据库名称的末尾。你可能会发现发现这和自己解决问题,但无论如何,我提到它:
至少在我的版本的Rails的)做rake test
使用数据库字符串\0末给出了问题。它首先在复制开发数据库定义之前删除测试数据库,然后使用包含测试数据库名称的SQL命令字符串。这会导致错误,因为字符串中间有\0

就我而言,我使用的本地开发数据库不会给出任何问题,因此我不需要使用该名称中的\0
这里是一个另类的黑客来解决(在mysql_adapter.rb原代码):

module ActiveRecord 
    module ConnectionAdapters 
    class MysqlAdapter 

     alias_method :old_execute, :execute 

     def execute(sql, name = nil) #:nodoc: 
     # This is needed because database names can end with "\0" to fix 
     # the issue with "handshake" when mysql server is newer than the gem 
     # requires. E.g. called when loading the new test db when doing "rake test". 
     sql = sql.delete("\0") 

     old_execute(sql, name) 
     end 
    end 
    end 
end 
+0

您是我的英雄 – elju 2015-05-13 16:00:24