6
votes

Why is the following error occurring?

QueryException SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

My .env file is as follows:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:P7auDP3AGgfkYLPbu+2/m7RCLc42Sip/HuXLLQFZiYs=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=student_management
DB_USERNAME=root
DB_PASSWORD=
6

6 Answers

8
votes

You should clear the cache after changing info in the .env file.

Run the following commands:

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache  
1
votes

It's either you edit a wrong file or you have not saved the .env yet. Because in your error message, it looks like you access the database using user homestead on localhost database, not root on student_management. Make sure you edit the correct .env, not .env.example. cheers

0
votes

Add the blank quotes in front of password like this

DB_PASSWORD=""

In the case if you have an empty password.
Hope this solution will work

0
votes

Cleaning out the system caches...for example for the PhpMyStorm IDE

On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart PhpStorm or both.

0
votes

You can use these commands to solve the problem

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache 

These commands are use to clear the cache.

0
votes

sudo mysql -u root -p

1-CREATE USER '**root**'@'localhost' IDENTIFIED BY '**1234**';

2-GRANT ALL PRIVILEGES ON *.* TO '**root**'@'localhost' WITH GRANT OPTION;