Can't connect to MySQL database PHP7
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:
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
59707
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
-
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?0 -
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?0 -
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?
Do you have root access on this server?0 -
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: 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:[myuser@server ~]$ 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]>0 -
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:
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:[myuser@server ~]$ 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! 59931 59927 599350 -
Are you sure that ssh service is running on port 22? Please contact your hosting provider and ask whether you have shell access and confirm the ssh port number. 0 -
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. 0
Please sign in to leave a comment.
Comments
7 comments