Error when attempting to access SQL database: Access denied for user 'username'@'localhost' (using password: YES)
I am attempting to access a SQL database through php, but receive the following error, when an attempt is made:
Uncaught mysqli_sql_exception: Access denied for user 'username'@'localhost' (using password: YES)
I have verified that the username and password are correct and, following advice from other posts, have also confirmed that the database user has all privileges, added the cpanel shared ip address, my local ip address, and '%' as remote access hosts; and both reset my cpanel password and removed the .my.cnf file, in my home directory.
This is the php code that I am using to attempt a connection:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I receive the same error when I use localhost:3306, the port used by phpMyAdmin.
I received a different error when I used localhost:2086, the port used for the cpanel file manager:
PHP Warning: Packets out of order. Expected 0 received 80. Packet size=5526600 PHP Warning: mysqli::__construct(): Error while reading greeting packet. PID=4123029
When testing other ports, I received:
Uncaught mysqli_sql_exception: Connection refused
-
Hey there! Do you see anything that may be helpful in the MySQL log? The default location on a cPanel server for that log file is /var/log/mysqld.log.
I'm wondering if it could be related to this bug:
https://bugs.mysql.com/bug.php?id=118447
but hopefully the logs would show us more.
0 -
Hi, thank you for the response!
It looks like I do not have a MySQL log in my directory. The /var/ folder is empty, aside from /cpanel/styled/ and no results appeared when I searched for the file.
0 -
These would be root-level folders, so if you only have cPanel access to the server you wouldn't be able to see that log file.
0
Please sign in to leave a comment.
Comments
3 comments