When using a few different Unix environments for development, the location of the socket for MySQL tends to vary quite a bit. Having to keep your database config different from the tree is a pain.
Luckily, there is a neat, but not widely known fix for this issue. It turns out that the YAML files used for Rails configuration are actually passed through the ERB. Now I can use this and it works without modification:
development: adapter: mysql database: development username: root password: host: localhost socket: <%= [‘/opt/local/var/run/mysql5/mysqld.sock’, # darwinports ‘/opt/local/var/run/mysqld/mysqld.sock’, # darwinports, again ‘/var/run/mysqld/mysqld.sock’, # ubuntu/debian ‘/tmp/mysql.sock’].select { |f| File.exist? f }.first %>
yes, I know this isn’t mindblowing, but seriously… in the real world of development… isn’t it nice to get rid of the nits that pile up and frustrate everyone.
Interesting, I actually just hit this when I was hacking on the plane, my solution was actually just to drop the socket line altogether and let rails use TCP instead of domain sockets. I figured for development it wasn’t such a big deal. Pretty cool find though.