Laravel 连接被拒绝错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34893651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:04:11  来源:igfitidea点击:

Laravel Connection Refused Error

phplaravelauthenticationconnection-refused

提问by Ollie

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 refusederror.

我正在尝试向 Laravel 5 项目添加身份验证(使用make:auth)每当我尝试“注册”时,都会收到SQLSTATE[HY000] [2002] Connection refused错误消息。

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

网上的回应是将 localhost 更改为 127.0.0.1 和 vise-vera,但这对我不起作用。

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

有人知道吗?谢谢(我在 OSX 上,如果这有什么不同的话)

.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,
        ],

采纳答案by krishnakumar kk

try adding mysql port in your database.php

尝试在 database.php 中添加 mysql 端口

        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'port'      => '33060',//your mysql port

回答by Imtiaz Pabel

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.

如果您使用 MAMP,请务必添加 unix_socket 键,其中包含 mysql.sock 驻留在 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'    => '',
),