Hello.

Laravel 5

When the application starts in the browser, it gives the following error, that there is no access to the database.

Login and password are correct, because I went under them to the mysql console with the following command: mysql -u root -p

'Illuminate \ Database \ QueryException' with message 'SQLSTATE [28000] [1045] Access denied for user' user '@' localhost '(using password: YES) (SQL: select count (*) as aggregate from areas where area_type = 0 ) 'in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:770

I do not get why there is no access? If it matters, the application is located on a remote server; this is not a local host.

In .Env indicated data to connect to the database:

 PP_ENV=local APP_KEY=base64:jkSYertretVUuiJJr7k+TzJretreUExhJ/Mdr4i3Jg= 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=databasename DB_USERNAME=user DB_PASSWORD=frefrefaxc 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_KEY= PUSHER_SECRET= PUSHER_APP_ID= 

database.php

 'default' => env('DB_CONNECTION', 'mysql'), 'connections' => [ 'sqlite' => [ 'driver' => 'sqlite', 'database' => env('DB_DATABASE', database_path('database.sqlite')), 'prefix' => '', ], 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '5432'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'prefix' => '', 'schema' => 'public', 'sslmode' => 'prefer', ], ], 

    2 answers 2

    Login and password are correct, because I went under them to the mysql console with the following command: mysql -u root -p

    Judging by the command, you are logged in as root and not user

    • No, I just copied it quickly. but in general came mysql -u user -p - Stefan Hansch
    • Well, it began - "oh, I copied it wrongly, wrote it wrong, and generally code from another window." And all this despite the fact that the error message is nowhere more clearly, and there is no point in asking questions after it. - Ipatiev
    • thank. It turns out you had to clean the cache. and now the environment variables have been updated. - Stefan Hansch

    After changing the values ​​of the environment variables in .env, it was necessary to clear the cache and everything fell into place:

     php artisan cache:clear php artisan config:cache