简体   繁体   English

Rails rake db:setup在服务器上失败:无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器

[英]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.

相关问题 延迟作业-耙作业:清除原因“无法通过套接字'/tmp/mysql.sock'连接到本地MySQL服务器(2) - Delayed Job - rake jobs:clear causes "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) `connect':无法通过套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器(Mysql2 :: Error) - `connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error) Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' - Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) - Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) - Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) Rails应用程序无法连接到mysql,无法通过socket'/var/run/mysqld/mysql.sock'连接到本地MySQL服务器(2)(Mysql2 :: Error) - Rails application unable to connect to mysql, Can't connect to local MySQL server through socket '/var/run/mysqld/mysql.sock' (2) (Mysql2::Error) MySQL地狱......无法连接数据库/tmp/mysql.sock - MySQL hell… can't connect to database /tmp/mysql.sock 无法通过socket '/var/run/mysqld/mysqld.sock Circle Ci/Rails/Mysql 连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock Circle Ci/Rails/Mysql Rails:无法通过套接字连接到本地MySQL服务器 - Rails: Can't connect to local MySQL server through socket RoR+Mysql (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error) - RoR+Mysql (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM