php 无法通过 socket '/var/run/mysqld/mysqld.sock' 连接到本地 MySQL 服务器 (2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10720018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:53:32  来源:igfitidea点击:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

phpmysqlyiicloudcontrol

提问by Fotis

I am a newbie programmer, so I will need your help! Locally the webapp works ok with the db on it! When I uploaded the application on the cloudcontrol, it comes up with the following error:

我是一个新手程序员,所以我需要你的帮助!在本地,webapp 与 db 一起工作正常!当我将应用程序上传到 cloudcontrol 时,出现以下错误:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)!

CDbConnection 无法打开 DB 连接:SQLSTATE[HY000] [2002] 无法通过套接字 '/var/run/mysqld/mysqld.sock' (2) 连接到本地 MySQL 服务器!

I suppose I have not uploaded the db. This is the very first time I upload a webapp on a server so I do not know the exact steps that I have to follow in order to upload the db on a server. Cloudcontrol has documentation about mysql! I did follow the steps but the webapp comes with the same error!

我想我还没有上传数据库。这是我第一次在服务器上上传 web 应用程序,所以我不知道在服务器上上传数据库必须遵循的确切步骤。Cloudcontrol 有关于 mysql 的文档!我确实按照步骤操作,但 webapp 出现了同样的错误!

Could you please tell me what steps I have to follow in order to make it working? I am sure that this error is due to lack of knowledge!

你能告诉我我必须遵循哪些步骤才能使它工作吗?我确信这个错误是由于缺乏知识!

回答by Mihai Stancu

Most likely the SQL server resides on a separate machine which you need to address via a host name or IP.

很可能 SQL 服务器驻留在单独的机器上,您需要通过主机名或 IP 寻址。

This means that in your code you should replace localhostwith the hostname of the machine where the SQL server resides (ex.: mysql.s032.example.com).

这意味着在您的代码中,您应该替换localhost为 SQL 服务器所在机器的主机名(例如:)mysql.s032.example.com

Finding the address of the SQL machine should be easy enough if it's documented by the hosting company within their control panel. Or by asking the hosting providers' tech support to tell you the address.

如果托管公司在其控制面板中记录了 SQL 机器的地址,那么查找 SQL 机器的地址应该很容易。或者通过要求托管服务提供商的技术支持告诉您地址。

回答by Angelin Nadar

As a newbie, I think you havn't installed mysql-serverand tried to install phpmyadmin.

作为新手,我认为您还没有安装 mysql-server并尝试安装 phpmyadmin。

Go to synaptic package => select mysql-server => automatically necessary componeents will be selected => Mark them for installation => apply

转到突触包 => 选择 mysql-server => 将自动选择必要的组件 => 将它们标记为安装 => 应用

then, reinstall => phpmyadmin

然后,重新安装 => phpmyadmin

Works fine.

工作正常。

If the above doent work, then, Follow this

如果上述方法不起作用,那么,请按照此操作