laravel SQLSTATE[HY000] [2002] 连接尝试失败.. - 尝试从本地连接到远程服务器时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36914770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:41:58  来源:igfitidea点击:

SQLSTATE[HY000] [2002] A connection attempt failed.. - When attempting to connect from Local to remote server

phpmysqllaravellaravel-5.1hosting

提问by Moti Winkler

env file:

.env 文件:

APP_ENV=local
APP_DEBUG=true
APP_KEY= ...........

DB_HOST=srv3.linuxisrael.co.il
DB_DATABASE= name_of_my_database
DB_USERNAME=moti_winkler
DB_PASSWORD=1234567890

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Routes.php :

路线.php :

use App\User;

Route::get('/', function(){
    User::create(['first_name' => 'moti']);
    return view('welcome');
});

The error i get :

我得到的错误:

PDOException inConnector.php line 55:

SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Connector.php 第 55 行中的PDOException

SQLSTATE[HY000] [2002] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机没有响应而建立的连接失败。

My problem is that:

我的问题是:

I'm trying to connect from my computer - to my remote MySQL server

我正在尝试从我的计算机连接到我的远程 MySQL 服务器

And I don't understand why it doesn't work ?

我不明白为什么它不起作用?

What should I do to connect ?

我应该怎么做才能连接?

What am I missing ?

我错过了什么?

I am using Laravel 5.1

我正在使用 Laravel 5.1

回答by e4c5

Hardly a surprise. The mysql socket is rarely if ever left open for connections from the public facing interface. usually mysql port (3306) can only be accessed from the private network interface.

难怪。mysql 套接字很少为来自面向公众的接口的连接打开。通常mysql端口(3306)只能从私有网络接口访问。

Even if the socket was open, there are so many things that that go wrong including firewalls getting in the way and simple timeouts.

即使套接字是打开的,也会出现很多问题,包括防火墙阻碍和简单的超时。