How to fix failed migrations for “Lost connection to MySQL”

Yet another in the long series of "why does rails give such useless error messages?"  I could migrate in the development environment fine, but when i tried to migrate in the test environment, I got this:

C:\dev\radrailsws\snorb>rake migrate RAILS_ENV=test(in C:/dev/radrailsws/snorb)rake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_info

After a bit of digging I thought it was because the mysql account in the test environment is different from development, so I ran this to grant full permissions:

mysql> grant all on snorb_test.* to unit_test_userQuery OK, 0 rows affected (0.00 sec)

But that didn’t work either.  I ended up having to let the test environment use the root mysql account, which I didn’t want to do, but that certainly fixed the problem.  I’ve suspected there’s something funny going on with the test environment database credentials for a while, but I can’t quite pin it down.

Here’s the full set of errors I was getting from the system in case it helps anybody find this problem… 

C:\dev\radrailsws\snorb>rake migrate RAILS_ENV=test(in C:/dev/radrailsws/snorb)rake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_info

(See full trace by running task with --trace)

C:\dev\fritz\radrailsws\snorb>config\environments\test.rb

C:\dev\fritz\radrailsws\snorb>rake migrate --trace(in C:/dev/fritz/radrailsws/snorb)** Invoke migrate (first_time)** Invoke db:migrate (first_time)** Invoke environment (first_time)** Execute environment** Execute db:migraterake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_infoc:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:336:in `select'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:179:in `select_one'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:307:in `current_version'
  1. jobdud says:

    What versions are your mysql client vs mysql server?

  1. There are no trackbacks for this post yet.

Leave a Reply