简体   繁体   English

无法从php“拒绝连接”连接到MySQL

[英]Unable to connect to MySQL from php “Connection Refused”

MySQL is running on a dedicated Linux Mint Box. MySQL在专用的Linux Mint Box上运行。 I can connect to this box by IP every other way such as shell, Navicat MySQL but just not php. 我可以通过IP其他任何方式(例如shell,Navicat MySQL)连接到此框,但不能连接php。 And I am out of ideas. 而且我没有主意。 Any help would be greatly appreciated. 任何帮助将不胜感激。 I have checked and rechecked credentials. 我已经检查并重新检查了凭据。 I can also connect to mysql from the local mysql box using shell. 我也可以使用shell从本地mysql盒连接到mysql。 But when I try and connect to the box from a remote shell using "mysql -uroot -h:199.91.65.82 -p" I get an error again. 但是,当我尝试使用“ mysql -uroot -h:199.91.65.82 -p”从远程外壳连接到该盒时,再次出现错误。 Same error - "Connection Refused" 同样的错误-“连接被拒绝”

See screenshot of firewall rules (ufw) 查看防火墙规则(ufw)的屏幕截图

在此处输入图片说明

For all of those who care, I fixed the issue. 对于所有关心的人,我已解决了该问题。

After failing all traditional means, and realizing the amount of hours wasted, I went ahead and reformatted the db server and re installed all fresh. 在使所有传统方法失败之后,并意识到浪费了很多时间,我继续进行操作,重新格式化了数据库服务器,然后重新安装了所有新服务器。

Imagine then, my disbelief when upon connecting, I saw the same error - "Connection Refused" 想象一下,当我在连接时难以置信的时候,我看到了相同的错误-“连接被拒绝”

I relectantly then resorted to what I really really avoid doing - a real time port to port packet trace between the web server and db server using shell and tcpdump or similar. 然后我勉强地采取了我真正避免做的事情-使用shell和tcpdump或类似工具在Web服务器和db服务器之间实时跟踪端口数据包跟踪。 The issue was immediately revealed. 该问题立即被发现。 It wasnt the database server at all (of course not) - my web server that served php pages had an active entry in the firewall - requiring it to reject all outgoing 3306 traffic. 它根本不是数据库服务器(当然不是)-为php页面提供服务的Web服务器在防火墙中具有活动条目-要求它拒绝所有传出的3306通信。 Clearly, someone compromised my server. 显然,有人入侵了我的服务器。

Yes, connection was being refused. 是的,连接被拒绝。 But as in life, nothing is as it seems. 但是,就像生活中一样,一切似乎都没有。 The webserver, in hara-kiri mode, was rejecting its own traffic. Web服务器处于hara-kiri模式,拒绝了自己的流量。 Lesson learnt. 学习到教训了。

From the manual: 从手册中:

"The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled , and that the network port you specified is the one configured on the server." “错误(2003)无法连接到'服务器'(10061)上的MySQL服务器。该网络连接已被拒绝。您应检查是否有正在运行的MySQL服务器, 是否启用了网络连接以及您指定的网络端口是服务器上配置的端口。”

Almost certainly in your case you need to enable network connections on your mySQL server, via the admin panel. 几乎可以肯定,您需要通过管理面板在mySQL服务器上启用网络连接。

EDIT: See below for a link. 编辑:请参阅下面的链接。 Users have to have appropriate privileges. 用户必须具有适当的特权。

Mysql adding user for remote access MySQL添加用户进行远程访问

You can do this via mySQL workbench or editing the .ini file. 您可以通过mySQL工作台或编辑.ini文件来执行此操作。 You may have to restart the server. 您可能必须重新启动服务器。

See "Limit to host matching" field which determines or limits from which host the user may connect. 请参阅“限制主机匹配”字段,该字段确定或限制用户可以连接的主机。 在此处输入图片说明

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

相关问题 连接失败:连接被拒绝...来自 PHP 代码的 MySQL 数据库,但我可以从 phpmyadmin 连接 - Connection failed: Connection refused... for MySQL database from PHP code, but I can connect from phpmyadmin 无法连接到smtp(连接被拒绝) - Unable to connect to smtp (Connection refused) 尝试使用PHP进行连接时获取mysql“连接被拒绝” - Getting mysql “connection refused” when trying to connect using PHP Docker PHP MySQL 连接被拒绝 - Docker PHP MySQL connection refused 错误:无法连接到MySQL。 调试错误:2002调试错误:连接被拒绝 - Error: Unable to connect to MySQL. Debugging error: 2002 Debugging error: Connection refused 无法连接到:连接被拒绝 - cURL PHP - Failed to connect to : Connection refused - cURL PHP php中的socket_connect上的“连接被拒绝”错误 - “Connection refused” error on socket_connect in php PHP套接字连接-Telnet拒绝连接 - PHP Socket Connection - Telnet refused to connect PHP警告:fsockopen():无法连接到example.com:8010(连接被拒绝)CentOS SELinux - PHP Warning: fsockopen(): unable to connect to example.com:8010 (Connection refused) CentOS SELinux 当我尝试通过 android 应用程序通过 php 连接到 mysql 数据库时,连接被拒绝 - Connection refused when I try to connect via php to mysql database over android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM