xXSamXx's avatar

xXSamXx was awarded Best Answer+1000 XP

4mos ago

The issue was caused by an incorrect database password. Even though I had already copied/pasted the credentials multiple times, it seems there was a hidden character or formatting issue in the password.

I regenerated the password in cPanel, copied it again into .env, and the connection worked instantly. Sorry for that Thanks to everyone who took the time to help!

xXSamXx's avatar

xXSamXx wrote a reply+100 XP

4mos ago

The issue was caused by an incorrect database password. Even though I had already copied/pasted the credentials multiple times, it seems there was a hidden character or formatting issue in the password.

I regenerated the password in cPanel, copied it again into .env, and the connection worked instantly. Sorry for that Thanks to everyone who took the time to help!

xXSamXx's avatar

xXSamXx wrote a reply+100 XP

4mos ago

Thanks for the suggestion I tried to run FLUSH PRIVILEGES; but on shared hosting (A2Hosting) I don’t have the required privileges to execute that command — phpMyAdmin returns the usual “Access denied” message.

I’ve contacted A2Hosting support and asked them to check the MySQL user privileges on their side and to run a privilege reload if needed. I’ll update the thread as soon as they reply.

xXSamXx's avatar

xXSamXx started a new conversation+100 XP

4mos ago

Hi everyone, I’m stuck with a persistent SQLSTATE[HY000] [1045] error on a shared hosting environment (A2Hosting), and after 2 days of debugging I still can’t figure it out.

Here is the exact Laravel error:

SQLSTATE[28000] [1045] Access denied for user 'user-db'@'localhost' (using password: YES)

What’s strange is that the same database name, user, password and host work fine inside phpMyAdmin, but Laravel cannot connect.

✅ What I have already tested

  1. Checked .env values multiple times All values are correct:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db-name
DB_USERNAME=db-user
DB_PASSWORD="pw"

The user/password were copied directly from the hosting control panel and also tested manually.

  1. Tested PDO connection with a plain PHP script Created testdb.php:
$servername = "localhost"; // also tried 127.0.0.1
$username = "db-user";
$password = "pw";
$dbname = "db-name";

try {
  $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "Connected!";
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}

Result: Connection failed: SQLSTATE[HY000] [1045] Access denied for user So the issue is not Laravel, but the MySQL authentication at hosting level.

  1. Tried different DB_HOST values
  • localhost
  • 127.0.0.1
  • The server name from phpinfo: nl1-ss102
  • The hosting domain (suggested by support) None of them work.
  1. Cleared Laravel caches Ran:
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear

Also removed the entire bootstrap/cache folder. No effects.

  1. Recreated the database completely Deleted DB Created a new one with a new name Created a brand new MySQL user Granted ALL PRIVILEGES Copied fresh credentials into .env Still same 1045 error.

  2. Checked PHP configuration The MySQL extension is enabled. No custom socket path listed in phpinfo.

❗ Important note I have other Laravel applications on the same hosting using:

DB_HOST=localhost

…and they all connect to MySQL without any issue. Only this new site fails, even though configuration is identical.

Given all the tests above, what else could cause an Access Denied (1045) error even with:

  • correct user & password
  • correct host
  • correct database
  • privileges granted
  • working phpMyAdmin access Is there something specific to shared hosting (A2Hosting) that can cause misrouting or a wrong MySQL internal host, or does this mean the hosting provider hasn't created the user correctly at MySQL server level?

Any idea or angle would be appreciated.

Thanks in advance!