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?
- How To Solve SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) Error?
- Solution 1: Run artisan command
- Solution 2: Set Database Credentials in this way
- Solution 3: delete bootstrap/cache
- Conclusion
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?
- 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. - 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
- How To completely uninstall PHP in ubuntu?
- Warning: “continue” targeting switch is equivalent to “break”. Did you mean to use “continue 2”
- Undefined symbol ‘Route’. Intelephense
- The POST method is not supported for this route. Supported methods: GET, HEAD
- Array and string offset access syntax with curly braces is deprecated