[英]Rails rake db:setup fails on server: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
I am running rake db:setup on my server, and I am getting: 我在服务器上运行rake db:setup,并且得到:
Can't connect to local MySQL server through socket '/tmp/mysql.sock'
(I added RAILS_ENV=production) (我添加了RAILS_ENV = production)
This is on a ubuntu, nginx, passenger, mysql setup. 这是在ubuntu,nginx,passenger,mysql设置上。
Either MySQL isn't running, or it's not configured to put the sock-file in the right place. MySQL未运行,或者未配置为将sock文件放在正确的位置。 Run something like ps aux | grep mysql
运行类似ps aux | grep mysql
东西ps aux | grep mysql
ps aux | grep mysql
to check if it's running. ps aux | grep mysql
检查它是否正在运行。 If it's running and the error persists, check if the file /tmp/mysql.sock
exists. 如果它正在运行并且错误仍然存在,请检查文件/tmp/mysql.sock
存在。 You can configure it in /etc/mysql/my.cnf
您可以在/etc/mysql/my.cnf
进行配置
On my ubuntu machine its configured to /var/run/mysqld/mysqld.sock
. 在我的ubuntu机器上,其配置为/var/run/mysqld/mysqld.sock
。 Either change your mysql settings, or change config/database.yml
in your Rails app. 更改您的mysql设置,或在Rails应用程序中更改config/database.yml
。
I had this issue and after trying everything I discovered that this occurs if you install mysql after you have installed rails. 我遇到了这个问题,在尝试了所有方法之后,我发现如果在安装Rails之后安装mysql,就会发生这种情况。
Reinstalling rails solved the issue for me. 重新安装滑轨为我解决了这个问题。
Of course this advice is only relevant if iain's answer doesn't solve your issue ;-) 当然,仅当iain的答案不能解决您的问题时,此建议才有意义;-)
If you dont have the file /tmp/mysql.sock, create a symlink to the actual socket file. 如果您没有文件/tmp/mysql.sock,请创建一个指向实际套接字文件的符号链接。 You will have to locate it first, but mine was here: 您将必须首先找到它,但是我在这里:
/etc/mysql/my.cnf /etc/mysql/my.cnf
That should fix it, as long as mysql is actually installed and running, check using this: 只要可以实际安装并运行mysql,就可以解决此问题,请使用以下命令进行检查:
ps aux | ps aux | grep mysql grep MySQL的
我在/etc/mysql/my.cnf中更改了套接字,然后工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.