Laravel php artisan migrate command not working. error like Illuminate\Database\QueryException

I try to migrate the table like php artisan migrate than throw error

enter image description here

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = authentic and table_name = migrations and table_type = ‘BASE TABLE’) at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671

// If an exception occurs when attempting to run a query, we’ll format the error // message to include the bindings with SQL, which will make this exception a // lot more helpful to the developer instead of just the database’s errors. catch (Exception $e) { throw new QueryException( $query, $this->prepareBindings($bindings), $e ); }

Add Comment
1 Answer(s)

If you are using MAMP be sure to add the unix_socket key with a value of the path that the mysql.sock resides in MAMP.

'mysql' => [         'driver' => 'mysql',         'url' => env('DATABASE_URL'),         'host' => env('DB_HOST', '127.0.0.1'),         'port' => env('DB_PORT', '3306'),         'database' => env('DB_DATABASE', 'forge'),         'username' => env('DB_USERNAME', 'forge'),         'password' => env('DB_PASSWORD', ''),         'unix_socket' => env('DB_SOCKET', ''),         'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock', //add this line         'charset' => 'utf8mb4',         'collation' => 'utf8mb4_unicode_ci',         'prefix' => '',         'prefix_indexes' => true,         'strict' => true,         'engine' => null,         'options' => extension_loaded('pdo_mysql') ? array_filter([             PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),         ]) : [],     ], 
Answered on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.