Error connecting to remote MySQL

GoWilkes

Well-Known Member
Sep 26, 2006
557
21
168
cPanel Access Level
Root Administrator
I have two servers, and I recently upgraded one of them. The one that has been upgraded hosts the main MySQL database.

The other server has several sites that access this database. They all worked fine when accessing the old server, but now I'm getting this error:

Code:
Can't connect to MySQL server on '123.45.67.89' (4)
I haven't been able to find anything about the error code (4), so I'm at a loss.

Things I've done:

1. Made sure that I could log in to MySQL locally using the username and password on the remove server.

2. SSH'ed to the remote server and made sure that I could ping the new one.

3. Double checked that the remote server's IP was listed as an "Access Host" in cPanel.

4. Just to be safe, double checked that it's also listed as an "Access Host" in WHM.

5. Whitelisted the remote server's IP in my firewall (it wasn't blacklisted, anyway)

If it matters, I'm connecting via PHP:

Code:
$user = [username];
$pass = [password];

$dbh = mysql_connect("123.45.67.89", $user, $pass, false) or die(mysql_error());
I also tried using mysql_connect("example.com"...), and then tried specifying the port with mysql_connect("example.com:3306"...), but neither made any difference.

I'm sure that this is an issue of granting permission to the remote server, but where else do I need to grant it?
 

GoWilkes

Well-Known Member
Sep 26, 2006
557
21
168
cPanel Access Level
Root Administrator
I just tried and... no, it timed out:

Code:
# telnet 123.45.67.89 3306
Trying 123.45.67.89...
telnet: connect to address 123.45.67.89: Connection timed out
What does that mean?
 

es2alna

Well-Known Member
Mar 30, 2014
67
0
6
Egypt
cPanel Access Level
Root Administrator
That means there's something preventing you from connecting to the remote server.

Suggestions are:

  • The remote server blacklisted or denied the IP of the local server.
  • The remote server is denying connecting to port 3306.
  • The local server can't make remote connections to port 3306 (port blocked).
  • The local server blacklisted or denied the IP of the remote server.


Re-check all those 4 suggestions and I'm sure you will find the issue in one of them.

Thanks,
 

GoWilkes

Well-Known Member
Sep 26, 2006
557
21
168
cPanel Access Level
Root Administrator
I found it; it turns out that I needed to whitelist the main server in the firewall of the remote server.

I confused that the remote server's firewall was preventing it from making an outgoing connection, but... it was. Go figure.

Thanks for the help!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,215
363
Hello :)

I am happy to see the issue is now resolved. Thank you for updating us with the outcome.