Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RubyonRails MySQL#08S01Bad握手-降级MySQL?_Mysql_Ruby On Rails_Ruby_Ubuntu 10.04 - Fatal编程技术网

RubyonRails MySQL#08S01Bad握手-降级MySQL?

RubyonRails MySQL#08S01Bad握手-降级MySQL?,mysql,ruby-on-rails,ruby,ubuntu-10.04,Mysql,Ruby On Rails,Ruby,Ubuntu 10.04,我们最近在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

我们最近在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
我在谷歌搜索了一下,发现了一个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智能安装mysql-server-5.1=5.1.41-3ubuntu12.10


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

我已经修复了!降级MySQL成功了。一旦Django站点上线,我们将重新升级到5.1.61。下面是降级MySQL的命令:

sudo智能安装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获得了准确的版本。

我也遇到了同样的问题。请加上:

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

然后运行
rake gems:install

不必降级MySQL gem,而是可以修复数据库名称参数来修复
的“握手错误”问题

我发现:它工作得很好

可以在
config/database.yml

production:
  database: "itsalive_production\0"
  adapter: mysql
  host: localhost
  encoding: UTF8
  ...
编辑
如果使用数据库名称末尾带有
\0
的解决方案。您可能会发现这一点并自己解决,但我还是要提到:
(至少在我的Rails版本中)
使用末尾带有
\0
的数据库字符串会在执行
rake测试时出现问题。它首先删除测试数据库,然后再复制开发数据库定义,然后使用包含测试数据库名称的SQL命令字符串。这将导致<强>错误,因为在字符串中间的<代码> \0 < /代码>。< /P>
在我的例子中,我使用的是一个本地开发数据库,它不会产生任何问题,因此我不需要使用该名称的
\0

下面是另一种解决方法(mysql_adapter.rb
中的原始代码):


我认为降级到MySQL 5.1.41是处理这个问题的最好方法,如果你的数据库连接代码是集中的,也许可以使用链接中的解决方法?避免此问题的一个解决方法是在建立连接时不设置数据库。可能只是我对RoR不太熟悉,但我不确定如何做到这一点。数据库连接设置在
config/database.yml
中,我不知道如何在不指定该文件中的数据库名称的情况下让站点与MySQL接口。我确实尝试注释掉数据库名称,但出现了一个新错误:
未指定数据库。缺少参数:数据库。
我刚在从.49升级到.61时遇到同样的问题。在Debian Squeeze上,降级为:
sudo aptitude install mysql-server-5.1=5.1.49-3 mysql-client-5.1=5.49-3 mysql-common=5.1.49-3 mysql-server-core-5.1=5.1.49-3 libmysqlclient16=5.1.49-3
。请将此问题的答案添加到“未回答问题”列表中:)
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