Laravel PHP - SQLSTATE [HY000] [2002] php_network_getaddresses:getaddrinfo失败:提供nodename或servname,或者不知道

时间:2018-01-26 03:20:02

标签: php laravel

运行命令php artisan migrate

时,我不断收到这些错误
In Connection.php line 664:

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s  
  chema.tables where table_schema = homestead and table_name = migrations)     
In Connector.php line 67:

  SQLSTATE[HY000] [2002] Connection refused 

My.env文件包含:

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

我的database.php文件包含:

'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',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

任何想法有什么不对?我一直在网上寻求帮助,但到目前为止他们都没有。

1 个答案:

答案 0 :(得分:0)

尝试替代,

  1. 在phpmyadmin或sqlyog中创建新数据库,无论您拥有哪个。
  2. 根据该设置凭据和数据库名称。
  3. 然后是fire composer update,然后是composer dump-autoload和php artisan config:cache
  4. 然后再次检查其是否正常工作
  5. 我希望这能解决你的问题。