sqlstate(hy000 error 1045) access denied for user laravel

sqlstate(hy000 error 1045) access denied for user laravel

If you are working in Laravel application. And you are trying to fetch or insert data from the MySQL database. And then you get this error SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user ‘username’@’localhost’ (using password: NO).

This type of error comes in two conditions. First of all, you have not configured the database properly with laravel app., or else your Laravel app is cached. In this tutorial, you will find the solution of laravel SQLSTATE[HY000] [1045] Access denied for user ‘root’@’localhost’ (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user ‘username’@’localhost’ (using password: NO).

Laravel sqlstate(hy000 error 1045) access denied for user ‘root’@’localhost’ (using password: YES/NO)

There are two types of errors that occur when you work with MySQL database on Laravel. whose solutions are given below:

  • Solution 1 – SQLSTATE[HY000] [1045] Access denied for user ”@’localhost’ (using password: NO)
  • Solution 2 – SQLSTATE[HY000] [1045] Access denied for user ‘abua’@’localhost’ (using password: YES)

Solution 1 – SQLSTATE[HY000] [1045] Access denied for user ”@’localhost’ (using password: NO)

If you forgot to add the database name, username, and password in your Laravel app. then you will get this error SQLSTATE[HY000] [1045] Access denied for user ”@’localhost’ (using password: NO).

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

For this, you have to open the .env file in the Laravel app and add the database name, username and password.

Solution 2 – SQLSTATE[HY000] [1045] Access denied for user ‘abua’@’localhost’ (using password: YES)

If you have added database details in .env file but still you got this error. SQLSTATE[HY000] [1045] Access denied for user ‘abua’@’localhost’ (using password: YES).

So for this you have to clear the cache of your Laravel app. You can use the command given below.

Clear Configuration Cache: In some cases, Laravel might cache the database configuration. To clear the cache in laravel, run the following command in your Laravel project’s root directory:

php artisan config:clear

Conclusion

In this tutorial, you have found two solutions for SQLSTATE[HY000] [1045] Access denied for user ‘abua’@’localhost’ (using password: YES and No) laravel.

Recommended Laravel Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *