In the past few days, learning the Laravel framework encountered database problems.
PDOException in Connector.php line 55:SQLSTATE[HY000] [1045]
Access denied for user 'homestead'@'localhost' (using password: YES)
The solution to the problem is as follows
1. Confirm that the database.php file is configured correctly.
First check that the information you filled in database.php is correct.
2. Check the .env file
This is the default .env file
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
Take part corresponding database
I use the mysql database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
3. Modify the .env file
Modify the above part as follows
DB_CONNECTION=mysql
DB_HOST=[your db adress]
DB_PORT=[port(3306)]
DB_DATABASE=[db]
DB_USERNAME=[username]
DB_PASSWORD=[password]
Save after modification
4. Restart the service
The initial change was unsuccessful, and it took a long time to find that the cache was not cleared. . .
Clean the cache to restart the service
into the root directory on the command line, issue the following statement.
php artisan cache:clear
php artisan config:clear
php artisan serve
This is enough to refresh.