Fix for : Access denied for user 'homestead'@'localhost'
You are here because you are working on a Laravel Project and on Opening of the project web page you see this error.
[Illuminate\Database\QueryException] SQLSTATE[HY000]  Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) [PDOException] SQLSTATE[HY000]  Access denied for user 'homestead'@'localhost' (using password: YES)
[caption id="attachment_1105" align="aligncenter" width="1363"] Access denied for user 'homestead'@'localhost' Error[/caption]
The solution to this error is pretty simple. You have a
.env file in your project. The .env file contains different property variables which applies to your project environment.
This include database connection properties, Application key value , SMTP Details etc.
In the default
.env file the database settings are set to something like this
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
You need to change the
DB_PASSWORD as per your local mysql settings in the .env file of your project
Once you correct these property variables in .env file, you should be able to access your application page.
If you have already changed the database property variables in .env file and you are still not able to access your project.
Follow these two additional steps.
Open your terminal , Go to the project root directory and execute this artisan command.
php artisan config:clear
Restart your Apache server and refresh the page. You no longer see the Error.