2

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)"

Cugurel
  • 107
  • 1
  • 3
  • 9
  • you can follow [https://stackoverflow.com/questions/31154124/sqlstatehy000-1045-access-denied-for-user-usernamelocalhost-using-cakep](https://stackoverflow.com/questions/31154124/sqlstatehy000-1045-access-denied-for-user-usernamelocalhost-using-cakep) – Sambhaji Katrajkar Apr 27 '18 at 10:55
  • Possible duplicate of [SQLSTATE\[HY000\] \[1045\] Access denied for user 'username'@'localhost' using CakePhp](https://stackoverflow.com/questions/31154124/sqlstatehy000-1045-access-denied-for-user-usernamelocalhost-using-cakep) – Sakthivel A R Sep 28 '19 at 17:01

4 Answers4

1

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

Adam Kozlowski
  • 5,606
  • 2
  • 32
  • 51
  • I did them bu it is not solution sir. – Cugurel Apr 27 '18 at 11:28
  • User name Host name Type Privileges Grant Action root 127.0.0.1 global ALL PRIVILEGES Yes Edit privileges Edit privileges Export Export root ::1 global ALL PRIVILEGES Yes Edit privileges Edit privileges Export Export root localhost global ALL PRIVILEGES Yes Edit privileges Edit privileges Export Export – Cugurel Apr 27 '18 at 11:38
  • I have 3 users is this normal? – Cugurel Apr 27 '18 at 11:38
  • it depends on your configuration. did u try to connect with database without laravel, just for test? – Adam Kozlowski Apr 27 '18 at 11:49
  • Yes i connected. Even i migrated. i manually created tasks table but i didn't create a task model. – Cugurel Apr 27 '18 at 11:52
0

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

Markus
  • 407
  • 2
  • 9
  • 25
0
php artisan cache:clear
php artisan config:clear
php artisan optimize

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

Jinandra Gupta
  • 546
  • 2
  • 9
0

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

Geoffrey Kimani
  • 133
  • 1
  • 1
  • 7