Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zaster's avatar

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) - In Laravel 7

I am getting this error when i run (I am using laravel 7.9.2)

php artisan migrate
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = mydb and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675|

      +34 vendor frames
  35  artisan:37

Everything runs smoothly in the local environment

tried

php artisan config:cache
php artisan cache:clear

I can access the production database without any issue

My .env file should be good ( I am using other laravel versions in production and i haven't experienced any such issue)

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=root
DB_PASSWORD=mypassword

Note : I have upgraded the php version to 7.4.5

0 likes
6 replies
zaster's avatar
zaster
OP
Best Answer
Level 9

My database password was wrong

I was confused between the Database Connection Password and Database Password

3 likes

Please or to participate in this conversation.