Rails: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Solution 1:

The reason you are running into this error is because the database.yml config file of your rails application is specifying the location of the socket.

development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: myapp_development
  pool: 5
  username: root
  password:
  socket: /var/run/mysqld/mysqld.sock

Since your Ubuntu MySQL Socket is in a different location than your Snow Leopard MySQL Socket, you will have to create a symlink if you want to be able to share the same config file among different computers.

sudo ln -s /tmp/mysql.sock /var/run/mysqld/mysqld.sock

Note: I had to create the mysqld directory before I could put a symlink in it.