简体   繁体   中英

PHP Laravel : Access denied for user 'homestead'@'localhost' (using password: YES)

Can someone explain why I got this error and how to solve this? I read several same stackoverflow question but still doesn't work.

 PDOException in Connector.php line 119:
 SQLSTATE[HY000] [1045] 
 Access denied for user 'homestead'@'localhost' (using password: YES)

My .env file

APP_ENV=local
APP_KEY=base64:pAoq6D+Xq2VXHQ9/z1f2ecd5gD104FfBnp5w/UVTV0Q=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
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=

Thank you for your attention.

Link I've read :

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

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

Access denied for user 'homestead@localhost' .. in laravel 5

尝试清除配置缓存,例如:

php artisan config:cache

Did you try to assign your database values to the DB_FIELDS ?

DB_DATABASE=Database
DB_USERNAME=Username 
DB_PASSWORD=Password

example:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=to-do-app-db
DB_USERNAME=root
DB_PASSWORD=""

Another option: php artisan config:clear

All the details you need to configure based on your mysql server.

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

For example if your are using xampp, go to your phpmyadmin, settings, user account to get your username and password. By default it will be root as username and password is null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM