Can't connect to MySQL database PHP7

warbi2601

Registered
Jun 29, 2019
3
0
1
Manchester, UK
cPanel Access Level
Website Owner
Good afternoon,

I am trying to connect my PHP project that is hosted on my CPanel website to the MySQL database that i have setup on CPanel's PHPMyAdmin however I can't. I think it is because i am using the incorrect username and password to access the CPanel database (The project was initially setup on XAMPP and all worked fine before i attempted to host it however the credentials were just 'root' and no password).

The error i'm getting is - Access denied for user 'warbi260_warbi26'@'localhost' (using password: YES)

My Connection Code:

<?php
$dsn = 'mysql:host=localhost;dbname=warbi260_Events-Website';
$user = 'warbi260_warbi26';
$password = 'PASSWORDFORUSERACCOUNTHIDDEN';
try {
$pdo = new PDO($dsn, $user, $password);
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo ->exec("SET CHARACTER SET utf8");
}
catch (PDOException $e) {
echo 'Connection failed again: ' . $e->getMessage();
}
?>

Steps I've tried:

Tried the steps in CPanel's "MySQL® Databases" section which you can see in the picture below
Tried my CPanel username and password.
Resetting my CPanel password

upload_2019-6-29_15-29-42.png


Sidenotes:

The user account warbi260_warbi26 has full privileges on the DB
PASSWORDFORUSERACCOUNTHIDDEN is the password that is set to the user account 'warbi260_warbi26' but is hidden for obvious reasons

Any help would be greatly appreciated as I've been at this for hours!

Thanks in advance,
Josh
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
6,815
541
263
Houston
cPanel Access Level
DataCenter Provider
PASSWORDFORUSERACCOUNTHIDDEN is the password that is set to the user account 'warbi260_warbi26'
That's also the password you've set for the user in the MySQL Databases section of cPanel? Can you also access the MySQL command line interface with that user and password?
 

warbi2601

Registered
Jun 29, 2019
3
0
1
Manchester, UK
cPanel Access Level
Website Owner
That's also the password you've set for the user in the MySQL Databases section of cPanel? Can you also access the MySQL command line interface with that user and password?
Thank you for the reply, I have been looking for it for a while but I cant find a way of getting onto a MySQL command line through CPanel? Can you point me in the right direction please?
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
6,815
541
263
Houston
cPanel Access Level
DataCenter Provider
You shouldn't need root access to the server to access the mysql command line. Your user does need to have shell access. You can use the terminal feature if available within cPanel or your can access using ssh.

Once logged into the server at the command prompt you would just type:

Code:
mysql -u $user -p
You'll be prompted for the user's password, if correct you should be in the MySQL commandline interface when complete and receive a message similar to the following:

Code:
[[email protected] ~]$ mysql -u mydbuser -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 765
Server version: 10.3.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [mydbuser]>
 

warbi2601

Registered
Jun 29, 2019
3
0
1
Manchester, UK
cPanel Access Level
Website Owner
You shouldn't need root access to the server to access the mysql command line. Your user does need to have shell access. You can use the terminal feature if available within cPanel or your can access using ssh.

Once logged into the server at the command prompt you would just type:

Code:
mysql -u $user -p
You'll be prompted for the user's password, if correct you should be in the MySQL commandline interface when complete and receive a message similar to the following:

Code:
[[email protected] ~]$ mysql -u mydbuser -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 765
Server version: 10.3.16-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [mydbuser]>


Hi Lauren,

Thanks again for the reply and apologies for the delay. I tried connecting via SSH but can't get it to work. I tried following the cPanel documentation and a cPanel youtube video but ended up with the same "Connection timed out" error. I even tried downloading puTTy but that is giving me a similar error message.

Apologies again I'm new to this!

upload_2019-7-10_20-32-31.png

upload_2019-7-10_20-29-54.png

upload_2019-7-10_20-36-3.png
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
6,815
541
263
Houston
cPanel Access Level
DataCenter Provider
Do you have the terminal feature available in your cPanel account? If you did it would be present at /var/cpanel/terminal

Otherwise, to further troubleshoot the MySQL issue as well as shell access I'd suggest contacting your provider.