mysql_connect 返回“无法通过套接字连接到本地 MySQL 服务器";在远程主机连接上? [英] mysql_connect returning "Can't connect to local MySQL server through socket" on remote host connection?

查看:46
本文介绍了mysql_connect 返回“无法通过套接字连接到本地 MySQL 服务器";在远程主机连接上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台服务器返回了一个意外的、间歇性的错误,想知道是否有人以前经历过或者可以猜测可能会发生什么.到目前为止,我的搜索一直没有结果.

I have a server that's returning an unexpected, intermittent error and wondering if anyone has either experienced it before or can guess what might be going on. My search has so far has been unfruitful.

我以通常的方式使用 mysql_connect() 连接到远程 mysql 服务器,但在过去 2 周(一天几次),与数据库的连接失败,并且出现无法连接到套接字的错误?

Im connecting to a remote mysql server using mysql_connect() in the usual way, but for the last 2 weeks (couple of times a day) the connection to the database fails and I get an unable to connect to socket error?

Error: 2002 - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

显然,这是出乎意料的,因为我正在尝试连接到远程主机.如果远程主机不可用,mysql_connect 是否默认为 localhost?我不知道它会这样做,文档中也没有说它会这样做.

Obviously this is unexpected as Im trying to connect to a remote host. Does mysql_connect default to localhost if the remote host is unavailable? I've not known it to do that, and nothing in the docs that say it does.

失败的连接、各种文件似乎没有任何模式,而且它在一天中的各种时间都会发生.我认为这可能与网络流量有关,因为如果您立即刷新页面,它可以正常连接,但我很困惑为什么我会收到无法连接到套接字的错误.

There doesn't seem to be any pattern to the failed connections, various files and it happens at all sorts of time of day. Im thinking it might be network traffic related, because if you refresh the page straight away it connects fine, but am confused as to why Im getting an unable to connect to socket error.

数据库提供商已检查但无法找到服务器本身的问题.有人有什么想法吗?

the database provider has checked and are unable to find an issue with the server itself. anyone have any ideas?

推荐答案

ok, facepalm 时刻……在这打击了我多年之后,我终于找到了 mysql_error() 报告套接字错误的原因.在我的代码中有一个我没有注意到的 mysql_select_db() ,那就是报告套接字错误,因为没有打开的连接可供使用.

ok, facepalm moment... after this hitting me for ages I finally found why mysql_error() was reporting the socket error. in my code there was a mysql_select_db() that I didnt notice and it was that, thats reporting the socket error as there is no open connection for it to use.

mysql_connect 报告的实际错误是 (2003) 无法连接到mysql.hostname.tld"上的 MySQL 服务器.我仍然倾向于某种 DNS 查找/网络流量问题,我目前使用 IP 地址进行连接以查看是否有错误.

actual error the mysql_connect is reporting is (2003) Can't connect to MySQL server on 'mysql.hostname.tld'. Im still leaning towards some sort of DNS lookup/network traffic issue, Im currently using the IP address to connect to see if that errors.

但就这个问题而言,答案是Im a numpty".

But as far as this question is concerned, the answer is "Im a numpty".

这篇关于mysql_connect 返回“无法通过套接字连接到本地 MySQL 服务器";在远程主机连接上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆