No such file or directory - /tmp/mysql.sock

 

转自: http://hi.baidu.com/royalchy/blog/item/591aac595a2b562f2834f059.html

So you installed Ubuntu, got all excited about developing your Rails application on it, and then…

No such file or directory - /tmp/mysql.sock)

No matter what you do, database connection doesn’t work. You reinstall Rails (of course you installed it via “sudo apt-get rails”, right??), reinstall MySql, recreate the database schema, change root’s password, install Kubuntu instead of Ubuntu… But it doesn’t work.

The reason for this error is quite simple, really: somewhere along Ruby’s Mysql driver, mysql socket is expected to exist at /tmp/mysql.sock. But that’s not where it is in Ubuntu. If you take some time searching, you’ll notice that the .sock file is actually on /var/run/mysqld - and it’s called mysqld.sock instead.

In fact, if you Google it, there is a closed bug entry on Rails’ tracking system regarding that problem, and the suggested solution there is to change your database.yml to add a link to the correct socket. Something like:

production:
adapter: mysql
socket: /var/run/mysqld/mysqld.sock

Which is obviously not a good idea, since you’ll end up creating new projects, moving to a different OS or whatever - and everything will break again.

So I tried a small patchwork to fool mysql’s driver, and then it works nicely:

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

That way you will actually HAVE a /tmp/mysql.sock file, as expected by mysql driver, and everything will connect just fine. Just like it’s meant to be. Amen!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值