QueryException SQLSTATE [HY000] [2002]无法连接到MySQL服务器

时间:2019-05-15 18:51:31

标签: php mysql laravel

QueryException SQLSTATE [HY000] [2002]无法连接到“ 127.0.0.1”(110)上的MySQL服务器

当我将此项目放入另一个服务器时,它可以正常工作。 服务器配置是否有问题?

在database.php中

'default' => env('DB_CONNECTION', 'mysql'),



'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => 'projapati',
        'username' => 'projapati',
        'password' => 'AHt!j![(dl',
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
    ],

    'pgsql' => [
        'driver' => 'pgsql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',
    ],

],

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

更改此

'host' => env('DB_HOST', '127.0.0.1'),

对此

'host' => env('DB_HOST', 'localhost'),