1

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)

enter image description here

7
  • what is the exact message? Does it say "Connection Refused" or "Can't connect to ...". What is the full message? Commented Aug 12, 2018 at 0:16
  • First you said, that you can connect via shell, then you said you can't. Do you meant you can connect via shell inside linux box? Commented Aug 12, 2018 at 0:34
  • Exact message: Connection refused Commented Aug 12, 2018 at 0:57
  • Exact message from remote shell session is: ERROR 2003 (HY000): Can't connect to MySQL server on '199.91.65.82' (111) Commented Aug 12, 2018 at 0:58
  • Exact message from PHP using the mysqli_connect() command is "Connection Refused" and the output from the mysqli_connect_error object is also "Connection Refused" Commented Aug 12, 2018 at 1:01

2 Answers 2

1

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. enter image description here

Sign up to request clarification or add additional context in comments.

10 Comments

Well, mysql is listening on port 3306 - based on the netstat -tulnp grep 3306 command I run on the box. And yes, port 3306 is the port as per netstat. Here is the exact output: tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19560/mysqld
How do I check if it has network connections enabled?
No luck; connection refused;
Seems like its a firewall issue and not a mysql issue since I can connect remotely, just not thru PHP
@Gautam Sharma ah OK that is another possibility. I have mySQL on an Ubuntu server, with PHP clients on Windows/PHP and I had to set up user permissions for remote use as indicated, before I could connect.
|
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.