简体   繁体   中英

Unable to connect to MySQL from php “Connection Refused”

MySQL is running on a dedicated Linux Mint Box. I can connect to this box by IP every other way such as shell, Navicat MySQL but just not 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. 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. Same error - "Connection Refused"

See screenshot of firewall rules (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. 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. 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. 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."

Almost certainly in your case you need to enable network connections on your mySQL server, via the admin panel.

EDIT: See below for a link. Users have to have appropriate privileges.

Mysql adding user for remote access

You can do this via mySQL workbench or editing the .ini file. You may have to restart the server.

See "Limit to host matching" field which determines or limits from which host the user may connect. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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