close

[Solved] SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO)

I am trying to connect my database with my laravel Project all Credentials are okay but Still I am facing the following error: SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO) in Laravel. In this Exerror article, We are going to learn about How to reproduce this error and we will discuss All Possible Solutions Lets Get Start with This Article.

How SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO) Error Occurs?

I am trying to connect my database with my laravel Project all Credentials are okay but Still I am facing the following error.

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

So here I am writing all the possible solutions that I have tried to resolve this error.

How To Solve SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO) Error?

  1. How To Solve SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) Error?

    To Solve SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) Error This error also occurs when You have used a Special character in your Database then You need to define all variable Always enclose them in "". Just like this: DB_PASSWORD=”your_password” If You have no Password for your Database then define DB_PASSWORD=””. And Now, Your error must be solved. Thank you.

  2. SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

    To Solve SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) Error You need to run all PHP artisan command one by one. Sometimes this error occurs by the cache where it is the config or route but running the PHP artisan command will resolve this error Just run all commands below one by one. First of all, Run this route-cache command: php artisan route:cache Then, Run this route-clear command: php artisan route:clear Now, Run this config-cache command: php artisan config:cache Then, Run this config-clear command: php artisan config:clear Now, optimize by running this command. And Now, Your error must be solved. Thanks.

Solution 1: Run artisan command

To Solve SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: NO) Error You need to run all PHP artisan command one by one. Sometimes this error occurs by the cache where it is the config or route but running the PHP artisan command will resolve this error Just run all commands below one by one.

First of all, Run this route-cache command.

php artisan route:cache

Then, Run this route-clear command.

php artisan route:clear

Now, Run this config-cache command.

php artisan config:cache

Then, Run this config-clear command.

php artisan config:clear

Now, optimize by running this command.

php artisan optimize

Here is All Command list.

php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize

And Now, Your error must be solved. Thanks.

Solution 2: Set Database Credentials in this way

This error also occurs when You have used a Special character in your Database then You need to define all variable Always enclose them in "". Just like this.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE="your_database_name"
DB_USERNAME="put_db_user_name _here"
DB_PASSWORD="put_db_password_here_if_have_set"

If You have no Password for your Database then define DB_PASSWORD=””.

DB_PASSWORD=""

And then run all artisan commands just like this.

php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize

And Now, Your error must be solved. Thank you.

Solution 3: delete bootstrap/cache

If Your Problem is still not resolved then just open bootstrap/cache/config.php and delete config.php file in the bootstrap/cache folder.

Conclusion

It’s all About this error. I hope We Have solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Leave a Comment