【问题标题】:Can't connect to remote mysql when I use domain as a host (Linode issue)当我使用域作为主机时无法连接到远程 mysql(Linode 问题)
【发布时间】:2015-11-09 18:44:18
【问题描述】:

例如,我使用 Laravel、PDO 驱动、Nginx、Ubuntu 12.04。

数据库设置。 example.com 指向 MySQL 服务器。此代码适用于 Google Cloud、AWS、DigitalOcean,但不适用于 Linode。

'driver' => 'mysql',
'host' => 'example.com',
'database' => 'db',
'username' => 'user',
'password' => 'password',

在 Linode 上我必须直接设置数据库服务器的 IP

'driver' => 'mysql',
'host' => '1.2.3.4',
'database' => 'db',
'username' => 'user',
'password' => 'password',

否则会报错

*1 upstream timed out (110: Connection timed out) while reading response header from upstream,

可能是什么问题?

【问题讨论】:

  • 你在服务器上安装了防火墙吗?检查 netstat 以检查它是否正在侦听通配符地址。
  • 是安装的防火墙或“它正在侦听通配符地址”
  • root@localhost:~# netstat -an | grep "LISTEN " tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN

标签: php mysql pdo linode


【解决方案1】:

如果您的服务器没有防火墙,它应该可以工作:

更改 mysql 配置

从编辑mysql配置文件开始

vim /etc/mysql/my.cnf

注释掉下面几行。

#bind-address           = 127.0.0.1
#skip-networking

如果没有找到skip-networking行,添加并注释掉。

重启mysql服务器。

service mysql restart

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2016-11-27
    • 2017-09-14
    相关资源
    最近更新 更多