gpt4 book ai didi

mysql - Ruby on Rails MySQL #08S01Bad handshake - 降级 MySQL?

转载 作者:IT老高 更新时间:2023-10-28 23:52:42 26 4
gpt4 key购买 nike

我们最近在我们的 Ubuntu 10.04LTS 服务器上从 MySQL 5.1.41 升级到 5.1.61。我们有一个古老的 RoR 网络应用程序,现在出现错误的握手错误:

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

我用谷歌搜索并偶然发现了 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

但是,这告诉我无法找到包“mysql-server-5.1”的版本“5.1.41-3ubuntu12.10”。我也尝试过 sudo aptitude install mysql-server-5.1=5.1.41,但这也没有用。我怎样才能让 aptitude 安装正确版本的 MySQL?

最佳答案

除了降级 MySQL gem,可以修复数据库名称参数来修复 "bad handshake" 问题。

我发现了这个:https://github.com/rubygems/rubygems/issues/423效果很好。

可以在 config/database.yml

中添加 "\0",而不是在 real_connect 中进行修改
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

关于mysql - Ruby on Rails MySQL #08S01Bad handshake - 降级 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9710427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com