The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Error connecting to remote MySQL

Discussion in 'General Discussion' started by GoWilkes, Apr 3, 2014.

  1. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    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?
     
  2. es2alna

    es2alna Well-Known Member

    Joined:
    Mar 30, 2014
    Messages:
    67
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
  3. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    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?
     
  4. es2alna

    es2alna Well-Known Member

    Joined:
    Mar 30, 2014
    Messages:
    67
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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,
     
  5. GoWilkes

    GoWilkes Well-Known Member

    Joined:
    Sep 26, 2006
    Messages:
    367
    Likes Received:
    1
    Trophy Points:
    18
    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!
     
  6. es2alna

    es2alna Well-Known Member

    Joined:
    Mar 30, 2014
    Messages:
    67
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    Really glad that the issue has been solved.

    Thanks for the letting us know.

    Greetings,
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,811
    Likes Received:
    671
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page