how to solve sqlstate[hy000] [1045] access denied in laravel

In this section, we'll discuss how to solve SQLSTATE[HY000] [1045] Access denied for user 'abua'@'localhost' (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO) while using laravel 9.


Example 1

Lets see why you got this error. SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO).

Its simple you forgot to give database name, username and password.

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
laravel  SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)

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

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=user_name
DB_PASSWORD=your_password


Example 2

Lets see why you got this error. SQLSTATE[HY000] [1045] Access denied for user 'abua'@'localhost' (using password: YES)

Some time you give DB_USERNAME or DB_PASSWORD wrong name that why you got 1045 password yes error.

laravel SQLSTATE[HY000] [1045] Access denied for user 'abua'@'localhost' (using password: YES)

laravel SQLSTATE[HY000] [1045] Access denied for user 'abua'@'localhost' (using password: YES)

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database_name
DB_USERNAME=add correct username
DB_PASSWORD=correct password