I cannot connect to MySQL server, but I still can open it via PHP Admin

I have taken a free wordpress hosting at Infinityfree to test out recently. For some programming I need to access the Wordpress Mysql database. I tried with following connection parameters

Server=sql305-infinityfree-com; (replace hyphen with dots, board is not allowing to post links)
Database=if0_39209049_wp687;
UID=if0_39209049;
PWD=xxxxxxxxxx

But could not connect from PHP, saying host does not exist. I then tried to read about this in this forums and in a topic with same name as this one from 2024, it become clear that those are fictituous host names for purpose of PhpMyAdmin only and I need to look for connection parameters at wp-config.php. I looked there and got these:

define( ‘DB_NAME’, ‘if0_39209049_wp687’ );
define( ‘DB_USER’, ‘39209049_1’ );
define( ‘DB_PASSWORD’, ‘xxxxxxxxx’ );
define( ‘DB_HOST’, ‘sql305-byetcluster-com’ ); (replace hyphen with dots, board is not allowing to post links)

Used those in a sample php file like this:

<?php
// Display errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$host='sql305.byetcluster.com'; //mysql host name
$user='39209049_1';  //mysql username   
$pass='xxxxxxxxxx;   //mysql password
$db='if0_39209049_wp687'; //mysql database

$con=mysqli_connect($host,$user,$pass,$db);
if($con) {
echo "Connection successful";
}
else {
  echo "Connection error";
}

try {
    $pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}
?>

But in both situation getting error as : PHP Warning: mysqli_connect(): (HY000/2002): 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.

Where am I getting wrong and what to do to fix this.

Then you are still not clear.

And this is quite telling.

It’s not that we set the hostname to some funny phpMyAdmin-only values. What’s actually happening is that you simply cannot connect to our database servers outside of our hosting. Regardless of what hostname you use.

You are kind of right that these hostnames are “fictitious”. But then it’s not like there’re two types of hostnames for one being fake and one being real — there’re no “real” hostnames for what you’re thinking of.


Now if you are actually connecting from within the hosting then it’s weird to get the message of host doesn’t exist because it’s unlikely, but anyways, the login info you’re using is created by Softaculous and can sometimes cause issues.

But again, this is for connections inside our hosting only. It doesn’t apply if you are connecting from outside.

5 Likes

Are you running this on a Windows machine by any change? Connection timeout errors can happen on all environments, but I have not seen it before with this particular message. And all the results I see for it are either from Microsoft or from companies that use a lot of Microsoft software.

If so, it means you’re not running the site on our hosting, which is also why you cannot connect to the database.

To develop your website on your own computer, please just backup the database of your hosting account, setup a MySQL server on your own computer and run the backup from that. Any data changed there won’t affect your real website, but usually that’s for the better.

4 Likes

Thank you for explaning, its clear now that I cannot connect to the free hosting database from outsideof hosting account

What I meant was while the host name from wp-config file (sql305-byetcluster-com) at least resolved to an IP, the one from Infinityfree control panel (sql305-infinityfree-com) has no DNS lookup. So i wrote that fictitious bit!

I was able to connect from within the site and it is running fine.

I needed to access the MySql DB from a different server to test out a bit of program to import-export data from the Wordpress backend. I have achieved my objective. Thank you, again.

Yes, the tested script is on a Windows server.

As I have explained in my previous comment,

"I was able to connect from within the ‘Infinityfree’ site and it is running fine.

I needed to access the MySql DB from a different server to test out a bit of program to import-export data from the Wordpress backend. I have achieved my objective. Thank you, again."