The error SQLSTATE [HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES) or (using password: Now) comes in two conditions, The first is that you have not configured the database correctly with Laravel, or else your application is cached.
There are two ways to fix the error, firstly clear the cache of the application and secondly configure the database in the application correctly.
Here are two solutions to fix sqlstate(hy000) (1045) access denied for user ‘root’@’localhost’ (using password: yes or no) in laravel:
Solution 1 – SQLSTATE[HY000] [1045] Access denied for ‘root’@’localhost’ (using password: YES)
To fix the error SQLSTATE[HY000] [1045] Access denied for user ”@’localhost’ (using password: Yes), Navigate to laravel app root directory and open your .env file and add the correct database details; as follows:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE= DB_USERNAME= DB_PASSWORD=
For this, you have to open the .env file in the Laravel app and add the database name, username and password.
Solution 2 – SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: No)
The error “sqlstate(hy000) (1045) Access denied for user ‘root’@’localhost’ (using password: no)” can occur in Laravel, when your Laravel application gets cached. Simply open your cmd or terminal and clear all the cache from laravel app by running php artisan config:clear
command into it.
php artisan config:clear
Conclusion
In this tutorial, you have found two solutions for SQLSTATE[HY000] [1045] Access denied for user ‘abua’@’localhost’ (using password: YES and No) laravel.