当运行 rake db:migrate
时,我得到这个错误:
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
我在这里查看了其他人的问题,但他们的解决方案都没有帮助我,例如:
解决方案一
mysql.server start
返回:
Starting MySQL
.错误!服务器在没有更新 PID 文件 (/usr/local/var/mysql/something.pid) 的情况下退出。
方案二
mysqladmin variables | grep socket
返回:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
补充说明: 我尝试使用自制软件重新安装 mysql,这是成功的,但我仍然收到相同的错误:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
最佳答案
我解决了!
首先,进入database.yml
将 host: localhost
更改为 host: 127.0.0.1
就是这样!
编辑:这暂时有效,但是当我今天重新启动计算机时,它开始抛出相同的错误。解决方法是从网站上安装 mysql,然后我的应用程序可以再次成功连接到 mysql。
关于Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41200297/