0

i cannot connect to database after clearing even php artisan is not working. here is how i clear config caches:

php artisan cache:clear

then it's cleared successfully but when i run:

php artisan config:cache

i got this error:

<pre><strong>ERROR:</strong> Can't connect to the database server. SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)</pre>% 

i also tried: composer dump-autoload but still no luck. Once in the past i got same error and i was able to solve it but no idea how. If someone knows solution then kindly explain it as well.

My php version: PHP 7.2.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 5 2018 05:00:15) ( NTS )

Thank you!

Ammad Khalid
  • 176
  • 2
  • 9

2 Answers2

0

User you are using to connect the database in not having privilege to connect, please provide that access to your db user

Keshav Kothari
  • 339
  • 1
  • 3
  • 12
  • **''** **(empty)** is not user ? also it's always using **localhost** as **hostname** even if i try to change it or not in **.env** file. But after spending few minutes i've find solution am i allowed to answer my own question? – Ammad Khalid Jul 20 '18 at 05:09
  • @AmmadKhalid you can comment the solution and use .env file to keep db credential. – Keshav Kothari Jul 20 '18 at 05:23
  • yes i always .env and i just post that solution as answer. But we are allowed to answer to own questions? if no one able to find answer before you? – Ammad Khalid Jul 20 '18 at 05:29
  • The issue is not with cache is issue is with the db user that you are using, please check you credential. – Keshav Kothari Jul 20 '18 at 05:41
  • https://i.imgur.com/RF1fRUw.png you can see i used **root** but it was showing **''** which means empty because maybe it don't cache the user. – Ammad Khalid Jul 20 '18 at 05:44
  • There is must be something wrong with my app. Otherwise it should cache completely. – Ammad Khalid Jul 20 '18 at 05:46
  • this detail should be share earlier for better understanding, try using composer update -o – Keshav Kothari Jul 20 '18 at 05:50
0

I don't know if i'm allowed to answer my own question or not. Let me know if it's not allowed to answer to your question.

In bootstrap directory which is located in root of your app. There i saw cache directory and then i just delete it and run:

composer dump-autoload

then it's works. But even if i try to run:

php artisan config:cache

it gonna be successful. But if after this you may get same error again:

php artisan serve       
ERROR: Can't connect to the database server. SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

After this i try to delete config.php inside bootstrap/cache/. it gonna work even after deleting that file.

Ammad Khalid
  • 176
  • 2
  • 9