Ruby on Rails MySQL #08S01握手错误 - 降级 MySQL?

2024-01-12

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

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 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也,但这也不起作用。如何让 aptitude 安装正确版本的 MySQL?


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

我找到了这个:https://github.com/rubygems/rubygems/issues/423 https://github.com/rubygems/rubygems/issues/423运作良好。

而不是进行黑客入侵real_connect可以添加"\0" in config/database.yml

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

EDIT
如果您使用该解决方案\0在数据库名称的末尾。你可能会发现这个并自己解决它,但我还是提到它:
(至少在我的 Rails 版本中)
使用数据库字符串\0最后在做时出现问题rake test。首先删除测试数据库,然后复制开发数据库定义,然后使用包含测试数据库名称的 SQL 命令字符串。这将导致error因为\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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Ruby on Rails MySQL #08S01握手错误 - 降级 MySQL? 的相关文章

  • Rails 中的字母分页

    我正在寻找 Rails 的宝石用于字母分页 我希望我可以在结果中找到第一个字母的列表 我的意思是 如果没有以 a 开头的行 我不希望 a 显示在分页链接上 这种宝石已经存在了吗 提前致谢 这根本不难创建 例如 如果您有一个find 也许像
  • Ruby 动态变量名

    有没有办法在 Ruby 中创建具有动态名称的变量 我正在读取一个文件 当我找到一个字符串时 会生成一个哈希值 e g file File new games log r file lines do l l split do p if p 1
  • 如何准确地衡量加载模型所需的时间?

    我想对加载模块 find by id 234 调用 所需的时间进行基准测试 另外 我如何跟踪加载页面所需的时间 我知道我在运行 Rails 服务器时得到此信息 但这是在调试模式下 我想要生产速度基准 可能吗 为了快速检查 我强烈建议检查基准
  • Rails:找不到 JavaScript 运行时。有关可用运行时的列表,请参阅 https://github.com/sstephenson/execjs。 (ExecJS::运行时不可用)

    自从几周前 Dreamhost 升级了服务器以来 我的网站就被破坏了 我一直在努力解决它并取得了一些进展 但我仍然坚持希望是最后的问题 我在 Ruby 1 8 7 上使用 Rails 3 1 1 并收到来自 PhusionPassenger
  • 使用 AJAX 和 JQuery 按设定的时间间隔刷新 Rails 部分

    I have a page in my rails application that looks like 现在 我有另一个用 python 编码的人工智能应用程序 它处理视频 显示在 Rails 应用程序页面的左侧 并使用捕获的车辆及其相
  • rake db 问题:迁移 -

    我无法为 Ruby on Rails 设置 MySQL 数据库 设置数据库并确保 config database yml 文件匹配后 我遇到了以下错误消息 U Rails alpha gt rake db migrate trace in
  • 如何根据域名更改视图格式

    我想知道是否有任何方法可以根据域名更改相同 Rails 应用程序的视图格式 例如 www domain com gt respond to format html api domain com gt respond to format xm
  • 是否有更好的一个衬垫来处理“除非something.new?||something[:key].nil?”

    有没有办法让这个内衬变得更好看 var params key1 key2 unless params blank params key1 blank 就在这里 var params params key1 params key1 key2
  • '回应?'与“定义?”

    如果我想检查是否定义了给定名称的方法 使用哪个更好 respond to or defined 从效率的角度来看 可以有理由使用defined 因为defined 是一个内置关键字 而respond to 是一种方法 因此前者可能更快 但另
  • 如何通过 Ruby 中的代理获取带有用户代理和超时的 URL?

    如果我需要通过某些方式获取 URL 我该如何获取 URLproxy 它必须有一个timeout最大 n 秒 和一个用户代理 require nokogiri require net http require rexml document d
  • RSpec 无法从 Factorygirl 中找到工厂

    我将在 Rails3 项目中将 RSpec 与 Factory Girl 一起使用 我已经安装了 Factory Girl 但它找不到工厂我有这个错误 Failure Error Factory build user should be v
  • 如何在实际作业中引用活动的delayed_job

    我正在研究一个解决方案来显示延迟作业的完成百分比 使用delayed job gem 目前 我的delayed jobs 表的数据库迁移如下所示 class CreateDelayedJobs lt ActiveRecord Migrati
  • 如何在不初始化Rails的情况下从schema.rb创建数据库?

    我正在尝试从 schema rb 创建所有表 我使用命令 rake db schema load 但是 这失败了 因为在我的一个初始化程序中 它引用了一个显然不存在的模型 表 因为数据库为空 我可以注释掉这些行 然后再次运行 schema
  • 处理铁路中 STI 子类路线的最佳实践

    我的 Rails 视图和控制器散布着redirect to link to and form for方法调用 有时link to and redirect to它们链接的路径是明确的 例如link to New Person new per
  • MySQL InnoDB 约束不起作用

    我偶然发现 innoDB 约束的奇怪行为 但找不到原因 我有包含数据的表格 下面列出了它们的结构 CREATE TABLE contents id int 10 unsigned NOT NULL AUTO INCREMENT title
  • MySQL:@@ 是什么意思?

    我正在阅读本页上的 MySQL 文档 http dev mysql com doc refman 5 1 en set statement html http dev mysql com doc refman 5 1 en set stat
  • Rails 的多个数据库不适用于远程数据库

    我有一个远程只读 postgres 数据库 它是通过 docker 实例维护的卡尔达诺数据库同步 https github com input output hk cardano db sync 我设法将开发数据库连接到它 它工作正常 但由
  • 通过 ruby​​ 进程共享变量

    我正在编写一个 gem 其中我必须分叉两个进程来启动两个 webrick 服务器 我想通过基类的类方法启动该服务器 因为应该只运行这两个服务器 而不是多个服务器 在运行时 我想调用这两台服务器上的一些方法来更改变量 我的问题是 我无法通过基
  • ruby rspec 不能与 simplecov 一起使用

    我安装了 simplecov gem 并添加了 require simplecov SimpleCov start 到spec helper rb文件 现在如果我在some file spec rb文件中包含spec helper rb并尝
  • 回形针/乘客 NotIdentifiedByImageMagickError:

    当我尝试上传照片时红宝石 on Rails http en wikipedia org wiki Ruby on Rails using 回形针 http github com thoughtbot paperclip在我的本地机器上它运行

随机推荐