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

Viewed 7720

I upload my project on C-panel and set my connection for database in my env file, it was ok for me with the same settings, but now i don't know why it's happening, this is error :

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

And this is my env file settings for database :

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thermota_db
DB_USERNAME=thermota_user
DB_PASSWORD= { my password }

i don't know this permissions in error, is my permissions_table ?

and why error for this table ?

4 Answers

Run this command:

php artisan config:cache

You are trying to use a different user that means that your root value is not used.

You need to cache your env field to use the values in it. That goes for every change you make as well.

Multiple reasons can be the cause.

  1. This can happen when the server has already been started before updating database details on your .ENV file.
  2. It could also be from inputting wrong database authentication details.

Solution

  1. Restart the server anytime you update values on your .ENV file.
  2. Ensure you use the correct authentication details or better still create a new database user.

if ur on online server do the following steps :

1 - locate to : /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
2 - add thoes line of code on the begining of this function :  createConnection($dsn, array $config, array $options)
3 - code to add : \Artisan::call('config:cache');
4 - refresh ur home page 
5 - remove the "\Artisan::call('config:cache');" line code
6 - enjoye ^^

I had the same issue and I couldn't run config:cache artisan command even with Artisan::call('config:cache');.

So I done this and solved my issue:

artisan config:cache caches all files from /config into a single array that it stores. It then reads all config variables from that array and ignores anything in .env or the /config files until you recach them. That's why it still works after deleting .env.

https://laravel.com/docs/5.6/configuration#configuration-caching

If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php file, which is the cache file config:cache generates.

Related