how to solve sqlstate[hy000] [2002] no connection in laravel

In this section, we'll discuss how to solve SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it in laravel 10.

laravel 10 solve SQLSTATE[HY000] [2002] No connection

laravel 10 solve SQLSTATE[HY000] [2002] No connection


Example

If you got this error plz try to check your XAMPP connection is on if you connection is off then on MySQL also on Apache.

laravel 10 xampp connection solve SQLSTATE[HY000] [2002]

laravel 10 xampp connection solve SQLSTATE[HY000] [2002]

If this solution not work then try to use below method.

1. Change .env file from 127.0.0.1 to localhost fixed it.

2. Run laravel cofig cache command php artisan config:cache

3. Check your config/database.php to see anything change.