Page 1 of 1
Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 2:53 pm
by Phillip911
Hi, i recently using forms and login tools to connect with MySQL, but i unable to connect it to my server. In the Cpanel i have created a database and mysql account, maybe i fill the wrong database name, server or username.
Did anyone can teach me what and how to fill it ?
Really appreciate
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 2:56 pm
by Pablo
Are you sure the settings are correct?
What is the error?
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 3:04 pm
by BaconFries
i have created a database and mysql account, maybe i fill the wrong database name, server or username.
As each host is different only yours will be able to confirm that the settings and the username and password are correct so please contact them to confirm these are what should be used.
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 3:14 pm
by Phillip911
It said
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Here are the image provided

--- Database that i fill

--- MyPhp main page

--- Username

--- MySQL table
The password is 100% correct as i have ask my hosing provider
Correct me if i fill wrong. Thanks and really appreciate
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 3:27 pm
by Pablo
It looks ok as far as I can tell.
What is the error?
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 3:29 pm
by Phillip911
When i uploaded and try signup an account, it said
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Any advice ?
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Tue Feb 22, 2022 3:35 pm
by Pablo
This can only be a configuration issue.
You will need to contact your web host about this
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Wed Feb 23, 2022 7:28 am
by quikflixx
Phillip911 wrote: Tue Feb 22, 2022 3:29 pm
When i uploaded and try signup an account, it said
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Any advice ?
Try using the address instead of localhost...
127.0.0.1:3306
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Wed Feb 23, 2022 8:46 am
by Adrian
Hello Phillip,
I don't know, but if I'm right, the error that you have say "Failed to select database" ??
if you want to connect to a database, 4 parameters are required:
1) DB Host -> in most cases "localhost". If your application is not placed on the same server where your application is hosted, you should enter here the IP address of your MYSQL Server. (Ex. 123.45.55.33)
2) DB name -> the name of the database
3) DB user -> the user that is authorized to use the database
4) DB password -> clear:-)
One more think: if the IP address of the server where your application is located and the IP Address of your MYSQL server is not the same, you MUST advise your MYSQL server to accept connections from other IP addresses. You can allow ALL IP addresses to connect to you MYSQL server or just a few.
For security reason I will suggest to accept connections just from the required IP address.
Regards, Adrian
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Wed Feb 23, 2022 12:16 pm
by quikflixx
Adrian wrote: Wed Feb 23, 2022 8:46 am
Hello Phillip,
I don't know, but if I'm right, the error that you have say "Failed to select database" ??
if you want to connect to a database, 4 parameters are required:
1) DB Host -> in most cases "localhost". If your application is not placed on the same server where your application is hosted, you should enter here the IP address of your MYSQL Server. (Ex. 123.45.55.33)
2) DB name -> the name of the database
3) DB user -> the user that is authorized to use the database
4) DB password -> clear:-)
One more think: if the IP address of the server where your application is located and the IP Address of your MYSQL server is not the same, you MUST advise your MYSQL server to accept connections from other IP addresses. You can allow ALL IP addresses to connect to you MYSQL server or just a few.
For security reason I will suggest to accept connections just from the required IP address.
Regards, Adrian
Thanks Adrian for the more detailed suggestions from what I gave. I was on my way out the door and didn't have time.
Jim
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Wed Feb 23, 2022 1:57 pm
by Adrian
Hello quikflixx,
sorry. reply to the wrong user
Regards, Adrian
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Wed Feb 23, 2022 1:59 pm
by Adrian
Hello Phillip,
I don't know, but if I'm right, the error that you have say "Failed to select database" ??
if you want to connect to a database, 4 parameters are required:
1) DB Host -> in most cases "localhost". If your application is not placed on the same server where your application is hosted, you should enter here the IP address of your MYSQL Server. (Ex. 123.45.55.33)
2) DB name -> the name of the database
3) DB user -> the user that is authorized to use the database
4) DB password -> clear:-)
One more think: if the IP address of the server where your application is located and the IP Address of your MYSQL server is not the same, you MUST advise your MYSQL server to accept connections from other IP addresses. You can allow ALL IP addresses to connect to you MYSQL server or just a few.
For security reason I will suggest to accept connections just from the required IP address.
Regards, Adrian
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 7:46 am
by Phillip911
quikflixx wrote: Wed Feb 23, 2022 7:28 am
Phillip911 wrote: Tue Feb 22, 2022 3:29 pm
When i uploaded and try signup an account, it said
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Failed to select database
Access denied for user 'phillip_login-test'@'localhost' to database 'phillip_login-test'
Any advice ?
Try using the address instead of localhost...
127.0.0.1:3306
I have try, but still can't
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 7:58 am
by Adrian
Hello Phillip,
can you connect to your MYSQL Server in Phpmyadmin?
Every host has his own access to the mysql server and this is phpmyadmin.
With this error message, I think this is the best way to beginn finding the error.
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 9:21 am
by Phillip911
Adrian wrote: Thu Feb 24, 2022 7:58 am
Hello Phillip,
can you connect to your MYSQL Server in Phpmyadmin?
Every host has his own access to the mysql server and this is phpmyadmin.
With this error message, I think this is the best way to beginn finding the error.
Yes, i able to connect MySQL with my Php admin. When i create a database at MySQL, Php my admin will update. Current error is still "Fail to connect database"

Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 12:42 pm
by Adrian
Hello Phillip,
----Fail to connect database mean that something is wrong.
If Phpmyadmin works and your application don't work AND all the settings are correct, than please take into consideration this point:
---------------------
One more think: if the IP address of the server where your application is located and the IP Address of your MYSQL server is not the same, you MUST advise your MYSQL server to accept connections from other IP addresses. You can allow ALL IP addresses to connect to you MYSQL server or just a few.
For security reason I will suggest to accept connections just from the required IP address.
--------------------
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 1:17 pm
by Phillip911
Adrian wrote: Thu Feb 24, 2022 12:42 pm
Hello Phillip,
----Fail to connect database mean that something is wrong.
If Phpmyadmin works and your application don't work AND all the settings are correct, than please take into consideration this point:
---------------------
One more think: if the IP address of the server where your application is located and the IP Address of your MYSQL server is not the same, you MUST advise your MYSQL server to accept connections from other IP addresses. You can allow ALL IP addresses to connect to you MYSQL server or just a few.
For security reason I will suggest to accept connections just from the required IP address.
--------------------
I have ask my host provider about the MySQL IP, they said the IP of the MySQL is same as the file manager. So i think it not the issue of IP, i still try and error
Re: Connect Cpanel MySQL issue (Not local host)
Posted: Thu Feb 24, 2022 2:17 pm
by Adrian
Hello Phillip,
I have another Idea
I put you here a php script, fill it correctly and upload him to your server.
After that, call the php file in the browser (your_Domain/path/file.php)and look what's happen.
If connection is established, you application has a problem.
If your connection fail, the database connection parameters are false.
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'db_name';
$dbuser = 'db_user';
$dbpass = 'db_passwd';
$dbhost = 'localhost or IP';
$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($link, $test_query);
$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
?>