Latest Laravel php artisan migrate command error : Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused

By | August 31, 2020

When I run php artisan migrate –seed command , I am encountering the following error :

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from information_schema.tables where table_schema = myDB and table_name = migrations and table_type = ‘BASE TABLE’)

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we’ll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database’s errors.
670| catch (Exception $e) {

671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|

  +34 vendor frames

35 artisan:37
Illuminate\Foundation\Console\Kernel::handle()

My Laravel project is running on:

lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster

Resolution:

I’m not 100% sure this will work for you but what worked for me was editing .env to change DB_HOST from 127.0.0.1 to localhost

Leave a Reply

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