0

I have mysql 8.0.15 for windows and I'm trying to connect from remote php webSite but always getting

2002: Connection refused

The code I use to test the connection is very simple

$dbHost = "HOST";
$dbUser = "root";
$dbPass = "password";
$dbDB = "DBNAME";
$dbPort = "9999";
echo "Conectando a $dbHost,$dbUser,$dbPass,$dbDB,$dbPort ";


$link = mysqli_connect($dbHost,$dbUser,$dbPass,$dbDB,$dbPort);

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);

I also try host:port and p:host:port and always getting the same error message.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Martin Varta
  • 766
  • 1
  • 7
  • 10
  • Sounds to me like the FireWall is keeping you out. You are not actually getting to MySQL yet – RiggsFolly Jan 09 '20 at 14:34
  • 1
    Can you clarify please. Where is running what. Sounds like the database is on your PC and the web site is on a remote hosted server somewhere. Is that right – RiggsFolly Jan 09 '20 at 14:36
  • There are too many possible duplicates. Please Google the error and try them out. – Funk Forty Niner Jan 09 '20 at 14:40
  • Also please read: https://stackoverflow.com/questions/58808332/should-we-ever-check-for-mysqli-connect-errors-manually – Dharman Jan 09 '20 at 14:46
  • mysql is running in a local PC (not mine) and PHP app is running on website. Connection work perfectly when port is 3306 but not when the port changes – Martin Varta Jan 09 '20 at 18:49

1 Answers1

-1

If you want to change the MySQL port, you have to edit the my.ini config-file on the MySQL server by setting port=<YOUR PREFERRED PORT>, then check if the port is forwarded and finally restart the MySQL server.

mapawa
  • 179
  • 1
  • 4
  • 16