Laravel: SQLSTATE[HY000] [2002] Connection refused

不问归期 提交于 2019-12-05 20:12:13

Try changing your DB_HOST from 127.0.0.1 to localhost. and if still not working try using the default mysql port to 3306

if you use laravel maybe your PDO PHP Extension not set. in your php.ini uncomment extension=php_pdo_mysql.dll

if you had no access to php.ini do this: add this to config/database.php in mysql section

'options' => [PDO::ATTR_EMULATE_PREPARES => true],

your code should be like this:

'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',
        'options' => [PDO::ATTR_EMULATE_PREPARES => true],
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

If you are trying to run php artisan migrate from host machine you need to set in .env conf file DB_PORT=33060 as that is a port vagrant/Homestead is listening on. But when i change that my application stop working. So i suggest ssh to vagrant and run php artisan migrate from VM and you will have no problems.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!