MySQL Forums
Forum List  »  PHP

Cannot connect to remote mysql.
Posted by: Tom Chambers
Date: September 21, 2016 07:48PM

Is there anything special I need to look for in connecting remotely to the data base other than the following:
1. In whm tell the system the ip to expect connecting.
2. In the cpanel tell the system the IP to expect connecting.
3. Make sure the port 3306 mysql is open.

Here is the scenario... I have a program that connects perfectly in the localhost mode. however no matter what I do it will not connect in remote.
This all began when a new commercial program that I recently got would not connect in remote..
So I simply threw together a simple php program to see what the problem was...
but so far still no results.. can anyone see anything wrong with my simple connect program that would cause a problem with remote connection.. again localhost connects perfectly..

My host on the site in question has claimed he opened the 3306 port for me on the site but my port scanner cannot see it open and he claims that its because its open for only that ip and the scanner cannot see it open since its not using that specific IP.. so that sounded reasonable so i left that one alone..

However things got worse.. I have antother site on hostgator and contacted them to open the 3306 port and they said on their servers its open as default. So i scanned and sure enough it says its open..

However I still cannot connect.. below I have included my tiny connect program with the hopes that someone could help me set it up to connect...

I have tried every possible scenario for the localhost.. as follows..
localhost = works great. fails fails
myip fails
myip:3306 fails.

So help me out here what else can i try.. I am at wits end..

The php program follows:
$dbhost = 'localhost';
$dbuser = 'myuser';
$dbpass = 'mypass';
$dbname = 'mydbname';
getData($domain, $dbhost, $dbuser, $dbpass, $dbname);

function getData($domain, $dbhost, $dbuser, $dbpass, $dbname) {
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
die('Could not connect: ' . mysql_error());
echo 'Connected successfully<br>';


The only entry that works is localhost.
Above you can see all the choices i have used for localhost when going remote.
Just to be sure that the server IP was being used I stopped navigating to the php file direct and let the cron run it each 5 min since it locks up for 3m in each call till the php times out with a fail..

The errors are basically saying Failed to connect and nothing more..

Options: ReplyQuote

Written By
Cannot connect to remote mysql.
September 21, 2016 07:48PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.