0

Possible Duplicate:
how to understand “can't connect” mysql error messages?

I have attempted to follow just about every tutorial I could find on this subject, to no avail. I'm trying to connect to a remote MySQL database through PHP, but it seems like the connection is timing out or something. This is my PHP code:

$link = mysql_connect('remote-server-ip:3306', $username, $password);
if($link){
    echo "Connected.";
}else{
    echo "Not connected: ".mysql_error();
}

When I browse to that page, it loads for about 30 seconds before displaying this:

Warning: mysql_connect(): Can't connect to MySQL server on 'remote-server-ip' (4) in /var/www/vhosts/*****/httpdocs/*****/*****.php on line 6

Here's what I've done on the remote server to try to allow this connection:

  • Added IPtables rules to allow connections from my server.
  • Set my.cnf to listen to all TCP requests
  • Added users to my database that can connect from my server's IP

Still nothing seems to be working. I could really use some help here.

Community
  • 1
  • 1
HellaMad
  • 5,294
  • 6
  • 31
  • 53

1 Answers1

1

If your waiting a period of time then it's likely the ip is not reachable. Try to ping the MySQL server first. Then try to telnet to it on port 3306. You should get a connection. Then see if you can connect to MySQL from the SQL server itself ie a local connection. Must do the basics first

Stacky
  • 106
  • 1
  • 8