1

I have been trying to run a simple query on my page but I get this error all the time.

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

The thing is that on consolo everything works fine with the same query.

I also tried creating a new user but it does not work either.

I am using XAMPP and Vagrant. Here are my .env and database.php

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=

With a test user:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=test
DB_PASSWORD=test123

database.php

'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
         PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),

Don't know what else to try, at a glance everything seems OK.

  • Does this answer your question? [Laravel shows error access denied for user](https://stackoverflow.com/questions/54824248/laravel-shows-error-access-denied-for-user) – Pooya Sabramooz Mar 22 '21 at 12:48

1 Answers1

0

Consider that sometimes config is not cached properly, use this:

php artisan cache:clear
php artisan config:cache

Pooya Sabramooz
  • 312
  • 2
  • 17