2
votes

I want to take all information from my database. Bu when i refresh the page error access denied occurs. How can i solve this. Can you please help me?

this is database.php;

'mysql' => [
        'driver' => 'mysql',
        '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' => '',
        'strict' => true,
        'engine' => null,
    ],

this is .env;

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:HMSysJsvQBx9lKnctKT2Z+7Gv//of2W8O18uD+5wO0o=
APP_DEBUG=true
APP_URL=http://localhost

 LOG_CHANNEL=stack

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

The error is: "SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from tasks)"

4

4 Answers

1
votes

Run:

php artisan config:clear
php artisan cache:clear

Or

php artisan config:cache

You will receive:

Configuration cache cleared!

Configuration cached successfully!

You must remember that .env datas are keep in laravel cache engine. So clear cache everytime when you make any changes in .env

0
votes

I think you have to clear your config cache. Restart your application or run php artisan config:cache from your command line.

0
votes
php artisan cache:clear
php artisan config:clear
php artisan optimize

Check on different browser better to check on chrome incognito after these commands.

0
votes

Check if your username and password in the .env file are correct. It might be that user doesn't exist, or that the user has a password