rake aborted! No such file or directory - /tmp/mysql.sock

Posted by Ryan Baxter Sat, 06 Oct 2007 20:40:00 GMT

If you’re running into the above error message when trying to perform a Rails migration on Debian or Ubuntu then you might try adding the following line to your database.yml file:

socket: /var/run/mysqld/mysqld.sock

My database.yml file looks sorta like this:

development:
  database: crunchlife_development
  adapter: mysql
  host: localhost
  username: mysql_user
  password: @!#?@!
  socket: /var/run/mysqld/mysqld.sock 

test:
  database: crunchlife_test
  adapter: mysql
  host: mysql.ryanbaxter.net
  username: mysql_user
  password: @!#?@!
  socket: /var/run/mysqld/mysqld.sock

production:
  database: crunchlife_production
  adapter: mysql
  host: mysql.ryanbaxter.net
  username: mysql_user
  password: @!#?@!

Good luck and happy migrations!

Comments

Leave a response

Avatar
George Comment_bubble 9 days later:
Thanks.. was looking for this fix. It works a treat on ubuntu 7.04.
Avatar
Ryan Baxter Comment_bubble 9 days later:
Huzzah! My blog helped somebody. :P
Avatar
andy Comment_bubble 22 days later:
Thanks - it helped me as well...
Avatar
Matthias (mw@zweiloewen.de) Comment_bubble 2 months later:
Yipiiiieeeeee, great! THX & greets from germany!
Avatar
Paul Fisher Comment_bubble 6 months later:
This is fantastic. You saved me from a bunch of headaches. Thanks!
Avatar
Ryan Baxter Comment_bubble 6 months later:
Great! I always like hearing when something I post helps someone out.
Avatar
Scott O Comment_bubble 9 months later:
Still helping people like me, Ryan. Thanks.
Avatar
Tyler Comment_bubble 9 months later:
You can also just symlink /tmp/mysql.sock to /var/run/mysqld/mysqld.sock
sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
I think that's a little DRYer solution to modifying each entry in your db.yml
Avatar
jannie Comment_bubble 10 months later:
Dankie!!
Avatar
Ryan Baxter Comment_bubble 10 months later:
Tyler - If you're developing and testing on the same server then it may be a teeny bit DRYer. I'm not so it's a irrelevant whether I create two symlinks or two config entries. Besides, I tend to forget symlinks between servers. If both entries are in your database.yml then you'll be less likely to forget a symlink migrating from dev to test.

Jannie - Welkom!
Avatar
namkhanh Comment_bubble 11 months later:
I used Ubuntu 8.0.4. I sort same upper but It display message "No such file or directory - /var/run/mysqld/mysqld.sock". please help me.
Avatar
Mark Comment_bubble 12 months later:
Woo hoo! Getting there now...
Avatar
rolo Comment_bubble about 1 year later:
many thanx from me also :-)
Avatar
jedzej Comment_bubble about 1 year later:
thanks a lot, you're good jedi;]
Avatar
victoryoalli Comment_bubble about 1 year later:
I solved the same problem changing the host: localhost to host: 127.0.0.1 development: adapter: mysql encoding: utf8 database: test_development pool: 5 username: root password: secret host: 127.0.0.1 I hope it would be of help to someone.
Avatar
eleze Comment_bubble about 1 year later:
In Centos 5.2 socket: /var/lib/mysql/mysql.sock thanks
Avatar
john Comment_bubble about 1 year later:
Just the solution I was looking for!
Avatar
ernz Comment_bubble about 1 year later:
thanks! it really helped me out!
Avatar
ayaz Ahmed Khan Comment_bubble about 1 year later:
Thank you, Ryan. That helped.
Avatar
ted Comment_bubble about 1 year later:
thanks for this. key.
Avatar
AlemQ Comment_bubble over 2 years later:
Tnx Ryan.
Avatar
Vasiliy Comment_bubble over 2 years later:
BIG thx! You can add for Centos 5.2 socket: /var/lib/mysql/mysql.sock in post, thanks
Avatar
Nando Comment_bubble over 2 years later:
Thanks from Spain!
Avatar
Daniel Comment_bubble over 2 years later:
Dude, this def helped me. Thank you!
Avatar
Rahul Comment_bubble over 2 years later:
Thanks Ryan
Avatar
Andrew Comment_bubble over 3 years later:
Thanks so much for this, worked a treat!