Ruby on Rails MySQL #08S01Bad handshake - downgrade MySQL?

久未见 提交于 2019-12-02 20:36:38

Instead of downgrade MySQL gem, it's possible to fix the database name parameter to fix the "bad handshake" problem.

I found this: https://github.com/rubygems/rubygems/issues/423 It's working good.

Instead of doing a hack in real_connect it's possible to add the "\0" in config/database.yml

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

EDIT
If you use the solution with \0 at the end of the database name. You probably will find find out this and solve it yourself, but I mention it anyway:
(at least in my version of Rails)
Using the database string with \0 at the end gives problem when doing rake test. It starts with deleting the test database before copying the development database definitions, and then using a SQL command string that includes the test database name. This will cause an error because of the \0 in the middle of the string.

In my case I'm using a local development database that doesn't give any problem so I don't need to have \0 in that name.
Here is a alternative hack to solve that (original code in 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

I fixed it! Downgrading MySQL did the trick. We'll re-upgrade to 5.1.61 once the Django site goes live. Here's the command to downgrade 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

I used apt-cache to get the exact version.

Awijeet

I also had the same issue. Please add:

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

Then run rake gems:install.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!