Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Connection Refused Error

I'm aware this is a repeat question, but none of the solutions online seem to be working for me.

I'm trying to add authentication to a laravel 5 project (using make:auth) Whenever I try to 'register', I get a SQLSTATE[HY000] [2002] Connection refused error.

The responses online have been to change localhost to 127.0.0.1 and vise-vera, but that isn't working for me.

Any idea anyone? Thanks (I'm on OSX, if that makes a difference at all)

.env
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=test
DB_PASSWORD=

database.php
'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'test'),
            'username'  => env('DB_USERNAME', 'test'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],
like image 417
Ollie Avatar asked Jan 07 '23 19:01

Ollie


2 Answers

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' => array(
'driver'    => 'mysql',
'host'      => 'localhost',
'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database'  => 'database',
'username'  => 'root',
'password'  => 'root',
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',
),
like image 124
Imtiaz Pabel Avatar answered Jan 10 '23 18:01

Imtiaz Pabel


try adding mysql port in your database.php

        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'port'      => '33060',//your mysql port
like image 28
krishnakumar kk Avatar answered Jan 10 '23 18:01

krishnakumar kk