Mysql
 sql >> Database >  >> RDS >> Mysql

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

Invece di eseguire il downgrade di MySQL gem, è possibile correggere il parametro del nome del database per correggere il "bad handshake" problema.

Ho trovato questo:https://github.com/rubygems/rubygems/issues/423 Funziona bene.

Invece di fare un hack in real_connect è possibile aggiungere il "\0" in config/database.yml

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

EDIT
Se usi la soluzione con \0 alla fine del nome del database. Probabilmente lo scoprirai e lo risolverai tu stesso, ma lo menziono comunque:
(almeno nella mia versione di Rails )
Utilizzo della stringa del database con \0 alla fine dà problemi quando si esegue il rake test . Inizia con l'eliminazione del database di test prima di copiare le definizioni del database di sviluppo e quindi utilizzando una stringa di comando SQL che include il nome del database di test. Ciò causerà un errore a causa del \0 nel mezzo della stringa.

Nel mio caso sto usando un database di sviluppo locale che non dà nessun problema quindi non ho bisogno di avere \0 con quel nome.
Ecco un trucco alternativo per risolverlo (codice originale 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