Laravel 5.1-Homestead MySQL连接.拒绝连接`没有这样的文件或目录` [英] Laravel 5.1 - Homestead MySQL connection. `Connection Refused` & `No such file or directory`

查看:263
本文介绍了Laravel 5.1-Homestead MySQL连接.拒绝连接`没有这样的文件或目录`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的.env文件是这样的时候:

When my .env file is like this:

 DB_HOST=127.0.0.1
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

终端php artisan migrate可以成功运行,但在localhost测试中会抛出:

Terminal php artisan migrate works successful but on localhost test, it throws:

Connector.php第50行中的PDOException:

PDOException in Connector.php line 50:

SQLSTATE [HY000] [2002]连接被拒绝

SQLSTATE[HY000] [2002] Connection refused

但是当我的.env文件是这样的时候:

But when my .env file is like this:

 DB_HOST=localhost
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

在localhost上,所有内容(注册)均正常运行,但在终端抛出时php artisan migrate:

On localhost everything (registration) works well however php artisan migrate on terminal throws:

[PDOException] SQLSTATE [HY000] [2002]没有这样的文件或目录

[PDOException] SQLSTATE[HY000] [2002] No such file or directory

我的database.php文件:

My database.php file:

      'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'homestead'),
        'username'  => env('DB_USERNAME', 'homestead'),
        'password'  => env('DB_PASSWORD', 'secret'),
        'port'      => '33060',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

推荐答案

在VM内,sql端口是3306.在homestead VM之外,主机仅转发到homestead VM上的SQL端口.这就是为什么33060指向3306的原因.

Inside the VM the sql port is 3306. Outside of the homestead VM the host machine just has a forward to the SQL port on the homestead VM. That is why 33060 points to 3306.

Laravel Homestead流浪者盒子数据库问题

这篇关于Laravel 5.1-Homestead MySQL连接.拒绝连接`没有这样的文件或目录`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆