Packets out of Order

Just a quick reminder to myself that the easiest fix to the “Packets out of order” error that Ruby on Rails sometimes throws is to edit the mysql adapter to prevent it from trying to load code that handles mysql’s new password hashing algorithm. Basically, in mysql 4.1.x, a new password hashing algorithm was introduced, and Ruby on Rails tries to connect using the new algorithm if it determines that your server version is greater than or equal to 4.1.x. If your actual mysql passwords are in the old format (16 characters), the connection will fail.

Several fixes have been suggested, including installing C bindings for the mysql driver (gem install mysql), which didn’t work for me. Ultimately, working from a cryptic suggestion by a coworker, I went into my ruby libs and edited /usr/local/lib/ruby/site_ruby/1.8/active_record/connection_adapters/mysql_adapter.rb and commented out the line seen commented out below:

begin
            require 'active_record/vendor/mysql'
            #require 'active_record/vendor/mysql411'
rescue LoadError

This prevents the code that does the 4.1.x substitutions from executing and allows your install of Ruby on Rails to play nicely with mysql users that have the old password format.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s