I am using Vagrant with fresh laravel 5.4 installed. After I run auth I have ran the migrate to migrate the MySQL tables. All of these process successful but when I try to login or register to test the system I am getting error:
SQLSTATE[HY000] [2002] Connection refused.
But my database working perfect since I already able to migrate the tables. Whats possible solution could be? check attached image (I'm using Ubuntu 16.04)

Try changing your DB_HOST from 127.0.0.1 to localhost. and if still not working try using the default mysql port to 3306
if you use laravel maybe your PDO PHP Extension not set. in your php.ini uncomment extension=php_pdo_mysql.dll
if you had no access to php.ini do this: add this to config/database.php in mysql section
'options' => [PDO::ATTR_EMULATE_PREPARES => true],
your code should be like this:
'mysql' => [
'driver' => 'mysql',
'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', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'options' => [PDO::ATTR_EMULATE_PREPARES => true],
'prefix' => '',
'strict' => true,
'engine' => null,
],
If you are trying to run php artisan migrate from host machine you need to set in .env conf file DB_PORT=33060 as that is a port vagrant/Homestead is listening on. But when i change that my application stop working. So i suggest ssh to vagrant and run php artisan migrate from VM and you will have no problems.
来源:https://stackoverflow.com/questions/42390640/laravel-sqlstatehy000-2002-connection-refused