简体   繁体   中英

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from `cats`)

I am building a basic CRUD app using Laravel 7 Homestead in a Vagrant VM. The root address http://crud-app.local.test works, but when I add a defined route ( http://crud-app.local.test/cats ) I get this error page:

Error message in browser when navigating to '/cats' route.

So far I have:

  • Verified my MySQL password matches in the .env file and in practice
  • Changed the MYSQL password so that it's no longer empty (and made sure it matches what's in the .env file)
  • Ran php artisan config:cache
  • Ran php artisan config:clear followed by php artisan cache:clear
  • Changed 127.0.0.1 to localhost
  • Made sure the database defined in the .env file exists ( crud )
  • Ran php artisan migrate (no errors, and the cats table exists in the crud database)
  • Restarted and re-provisioned the machine ( vagrant reload --provision )

I'm at a loss now.

Make sure that you give "root" permissions to read from the database that you've created. As it's root@localhost rather than root@127.0.0.1 sometimes mysql differentiates. Just check the permissions that root@localhost has for the database and if you update them, flush the privileges.

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