Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database Laravel php artisan migrate connection refused

When I use 'php artisan migrate' I get the following error message:

[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations)

[PDOException]
SQLSTATE[HY000] [2002] Connection refused

I've installed Laravel on a mac with XAMPP and have the following settings:

database.php

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

.env

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

I've tried several solutions I could find online, but none have worked so far.

like image 361
Femke Avatar asked May 05 '17 12:05

Femke


1 Answers

This is really anoying, but changing DB_HOST=127.0.0.1 to DB_HOST=localhost solves the problem. Give it a try (obviously your file permission must be the right one)

like image 146
Marcial Soto Avatar answered Sep 25 '22 14:09

Marcial Soto