Jun
20
MySQL Lost Connection error in Rails
June 20, 2006 | 4 Comments
I was working with Rails on my local development server tonight and was running into the MySQL ‘Lost Connection’ error. I read a couple other posts of others having problems on Win32 systems and privilege issues, however I am running Linux and the suggested fixes weren’t going to work for me. Apparently, mySQL was not liking how Rails was sending the username and password when initiating the connection through the socket. Not exactly sure why, but in case someone else runs into the issue, the quick fix is to create a mySQL user without a password. Add it to your database.yml file and restart the WEBrick server.
I am running mySQL 4.1.11, another solution might be to upgrade to the latest mySQL release.
Comments
4 Comments so far
I have been running under windows with MySql 5 with no problems. Using Mongrel for the production server with loadbalacing behind Apache 2.0. Works a treat. And with Rmagick
)
Campbell Xsive.co.nz
Hi Mike,
Thanks for the workaround!
I have the same issue, very strange. Two machines (dev and prod). The prod app, running FC4 as operating system, only runs with the dev database (password protected)… To have the prod app talking to the prod DB then I have to use your solution…
Thanks again
Fabrice.
MySQL 4.1 changed the authentication protocol (it now uses a different type of password hash). If you upgraded from a previous version of mysql, chances are your passwords are still in the old format. Since rails knows about the new format and tries to authenticate with new style passwords, it is unable to connect. Obviously this can be solved by simply not using passwords. But if you need password protection, just recreate the passwords in the new format (using the PASSWORD() function, i.e. SET password = PASSWORD(’newpass’)). Don’t forget to flush privs.
Mike, thanks for the info. We spent several hours troubleshooting this stupid issue before finding your solution.