A sketched picture of James' head

James Smith

Building a better future out of code

Problems with Rails and MySQL

Posted by

I recently reinstalled my laptop with Fedora Core 6, and when I went to fiddle with my prototype Rails project, I found that nothing worked. I had a bunch of problems, and I thought I'd note down the solutions here, in case anyone else had the same problem. So, forgive me, it's going to be techy for a while.

First, the thing wouldn't connect to the MySQL database at all, claiming that /tmp/mysql.sock didn't exist. Odd. Well, not that odd, in fact, because the MySQL RPM for FC6 creates its socket in /var/lib/mysql/mysql.sock instead of /tmp/mysql.sock. So, the addition of a socket line to config/database.yml and we're off again:

socket: /var/lib/mysql/mysql.sock

Next problem: the thing is now connecting, but when I try to recreate the tables using rake db:migrate, it complains thusly:

Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info

Bugger. Turns out, after some web research, that Rails has changed to new-style password authentication for MySQL. However, the FC6 MySQL installation hasn't, in order to keep compatibility with older clients. Fair enough. Again, it's a fairly simple fix. I had to change the appropriate setting from 1 to 0 in /etc/my.cnf:


I was feeling good at this point, and restarted the MySQL server, ready for my Rails app to spring into life. Alas, no, same problem. However, resetting the MySQL password using mysqladmin sorted it all out, and the thing is now happy.

mysqladmin -u user -p password xxxxx

If you're having similar problems, I hope this helps!


Add a comment