简体   繁体   English

PHP 无法连接到 MySQL 服务器

[英]PHP can't connect to MySQL server

I have a few PHP servers connecting to my MySQL server through my DNS redirect and the code is a normal mysqli-connection:我有几个 PHP 服务器通过我的 DNS 重定向连接到我的 MySQL 服务器,代码是一个普通的 mysqli 连接:

$db_link = mysqli_connect(server, user, passwort, database, port);

2 PHP servers can access the MySQL with this script, 2 can't and I have no idea where to search for the mistake in my system as they are running different Linux OS and PHP versions (5.3-5.8). 2 个 PHP 服务器可以使用此脚本访问 MySQL,2 个不能,而且我不知道在哪里搜索系统中的错误,因为它们运行不同的 Linux 操作系统和 PHP 版本 (5.3-5.8)。

Error message:错误信息:

Can't connect to MySQL server on 'servername' (111)无法连接到“服务器名”上的 MySQL 服务器 (111)

As two of them can connect through the DNS host, I think the MySQL and DNS server shouldn't be a problem.由于其中两个可以通过DNS主机连接,我认为MySQL和DNS服务器应该没有问题。

Has anyone an idea where the problem could be?有谁知道问题可能出在哪里?

Basic reasons:基本原因:

  • There is no MySQL server running at the specified host指定主机上没有运行 MySQL 服务器

  • Connection to the MySQL server is not allowed using TCP-IP.不允许使用 TCP-IP 连接到 MySQL 服务器。 Check the 'skip-networking' setting in the MySQL configuration file (my.ini on Windows, my.cnf on Unix/Linux).检查 MySQL 配置文件(Windows 上的 my.ini,Unix/Linux 上的 my.cnf)中的“skip-networking”设置。 It shall be commented out like '#skip-networking'.它应该像'#skip-networking'一样被注释掉。 If it is not commented out, then do it and restart the MySQL server for the change to take effect.如果没有注释掉,那么做并重新启动MySQL服务器以使更改生效。 SQLyog needs to connect using TCP-IP. SQLyog 需要使用 TCP-IP 进行连接。

  • Some networking issue prevents connection.一些网络问题阻止连接。 It could be a network malconfiguration or a firewall issue.这可能是网络配置错误或防火墙问题。 We have experienced sometimes that some firewalls (ZoneAlarm in particular) is blocking TCP-IP connections even if it claims to be disabled.我们有时会遇到某些防火墙(尤其是 ZoneAlarm)会阻止 TCP-IP 连接,即使它声称已禁用。 Most often it will help to uninstall and reinstall the firewall.大多数情况下,它有助于卸载并重新安装防火墙。

  • When trying to connect to a MySQL server at an ISP this error message often indicates that direct connection to MySQL has been blocked.当尝试连接到 ISP 处的 MySQL 服务器时,此错误消息通常表明与 MySQL 的直接连接已被阻止。 You must then use HTTP-tunneling or SSH-tunneling to connect.然后,您必须使用 HTTP 隧道或 SSH 隧道进行连接。

  • Also this FAQ may have relevant information.此常见问题解答也可能包含相关信息。 It describes some more special situations when connection to MySQL on Linux它描述了在 Linux 上连接 MySQL 时的一些更特殊的情况

http://faq.webyog.com/content/23/15/en/error-no-2003-can_t-connect.html http://faq.webyog.com/content/23/15/en/error-no-2003-can_t-connect.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM