-4

I'm trying to see all the tables from an external MySQL server. I've its IP address, username, password to connect & query their database. But when I try to query to show all the tables I get error message like this,

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host has failed
to respond. in G:\XAMPP\htdocs\test.php on line 2
Failed to connect to MySQL: Access denied for user ''@'localhost' to database 'thedb'

Here is my code,

<?php
$conn = mysql_connect("202.82.31.11", "abc_user", "abc123");
$select = mysql_select_db("thedb");

if(!$conn || !$select){
 echo "Failed to connect to MySQL: " . mysql_error();
}

$sql = "SHOW TABLES";
$result=mysql_query($sql);
echo $result;
?>

I was told to always connect from real IP 52.247.181.57. So what does it mean? Do I've to connect from my real IP? If so, how can I do that? I need to know the procedures. Your help would be much appreciated. Tnx. FYI, the IP here are all dummy/random IP for example purpose.

Ankit Chhatbar
  • 342
  • 2
  • 8
  • 19
Shihan Khan
  • 2,180
  • 4
  • 34
  • 67
  • *resource mysql_connect (**$server**,...* $server is the ip-address of the MYSQL-Server, mysql server access can be different for localhost and IP connecting ... see mysql.com for examples, btw use mysqli or PDO instead of mysql_* functions – donald123 Jan 08 '15 at 08:23
  • See if that IP address is linked to any url in hostfile, and then try using that in your PHP code. – Gaurav Dave Jan 08 '15 at 08:27
  • `because the connected party did not properly respond` - looks like your data packages are dropped somewhere along the route. Since you've been given instructions about the origin address it's quite likely the server provider rejects all packets but from a specific (range) of ip address(es), i.e. an exception rule in the firewall. – VolkerK Jan 08 '15 at 08:29
  • 1
    Slightly offtopic, but very important: stop using ``mysql_*`` functions: http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Stephan Vierkant Jan 08 '15 at 08:32
  • So far seeing the answers, I don't have privilege from my pc. Ok let me see if I can query on the target pc. Tnx for all your support. – Shihan Khan Jan 08 '15 at 08:43

2 Answers2

0

On the external server, you need to allow (whitelist) your IP address. If you have Cpanel on the remote server, go to Remote MySQL and allow your IP. Also, on the remote server, the port 3306 must allow incoming connections.

AndreiD
  • 57
  • 5
0

First go on http://whatismyipaddress.com/ and check your IP. If its not 52.247.181.57 then you don't have access to the mySQL server. You may request access to the server administrator via cPanel / Remote MySQL and give him your IP. However if you don't own a personal public IP I don't recommend this version.

besciualex
  • 1,872
  • 1
  • 15
  • 20