laravel报错SQLSTATE[HY000] [2002] Connection refused (SQL: select `name`, `value` from `admin_config`)

本地执行php artisan 命令报错如下:

admindeMBP:laravel56 admin$ php artisan config:clear

In Connection.php line 664:
                                                                               
  SQLSTATE[HY000] [2002] Connection refused (SQL: select `name`, `value` from  
   `admin_config`)                                                             
                                                                               

In Connector.php line 68:
                                             
  SQLSTATE[HY000] [2002] Connection refused  

网上很多资料让配置php.ini中的pdo_mysql.default_socket= /tmp/mysqld.sock文件。

也有让修改配置文件DB_HOST 127.0.0.1改成localhost

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', ''),
            '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,
        ],

上面两个方法配置没问题,但还是报错,查看laravel.log

[2019-02-18 01:48:26] local.ERROR: SQLSTATE[HY000] [2002] No such file or directory {"exception":"[object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /Users/admin/data/study_model/laravel56/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68)
[stacktrace]
#0 /Users/admin/data/study_model/laravel56/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(68): PDO->__construct('mysql:host=loca...', 'root', 'root', Array)
#1 /Users/admin/data/study_model/laravel56/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(44): Illuminate\\Database\\Connectors\\Connector->createPdoConnection('mysql:host=loca...', 'root', 'root', Array)

PDO连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”。

出现这个问题的原因是还是PDO无法找到mysql.sock或者mysqld.sock。

看配置文件中unix_socket参数没有配置,加上下面配置后,OK了。

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值