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

时间:2017-10-10 04:39:59

标签: php mysql laravel docker

我是Laravel的新手。我正在尝试使用资源控制器创建一个laravel CRUD。但是,当我尝试运行php artisan migrate时,我收到以下错误:

  

SQLSTATE [HY000] [2002]没有这样的文件或目录(SQL:select * from   information_schema.tables where table_schema = homestead和   table_name =迁移)

这是我的database.php

 'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'design'),
        'username' => env('DB_USERNAME', 'homestead'),
        'password' => env('DB_PASSWORD', 'secret'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

这是我的环境文件:

    APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:hLJn+XHKPjf5qEvROeyMMLIjw56Kg9RkXhZIlbjjne4=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=design
DB_USERNAME=homestead
DB_PASSWORD=secret

这是一个常见问题,我尝试了很多解决方案,但它们无法正常工作。请帮忙。

1 个答案:

答案 0 :(得分:1)

尝试使用PORT 3306并将localhost更改为127.0.0.1

例如

$result = Array ( 
    [Pakistan] => Array ( 
        [impression] => 110 
        [request] => 8 
        [click] => 5 
    ) 
    [India] => Array ( 
        [impression] => 20 
        [request] => 50 
        [click] => 5 
    ) 
);

foreach($result as $key=>$value)
{
    print_r($value['impression']); //try this to print impression
}