Digital Ocean 将一个 droplet 连接到另一个 droplet 的 MySQL DB

Digital Ocean connect one droplet to the MySQL DB of another droplet

我有 2 个液滴,都有一个 LAMP 堆栈 (Ubuntu 16.04)。两者都安装了 PHPMyAdmin,运行 一个 PHP 应用程序,并且有一个自动重定向到 https 的自签名 SSH 证书。

我想做的是从 Droplet 2 上的应用程序连接到 Droplet 1 上的 MySQL 数据库。我知道你可以通过 运行 宁一个 MySQL 服务器在 Droplet 1 上,但在这种情况下,两者都需要 运行 一个完整的 PHP 应用程序。

这是我已经做过和尝试过的:

我的 PHP 应用程序连接设置 (CodeIgniter 3.1.7)

$db['remotedb'] = array(
'dsn' => '',
'hostname' => 'PRIVATE IP OF DROPLET HERE', // in the format xx.xx.xx.xx so without https:// in front of it 
'port' => 3306,
'username' => 'user',
'password' => 'password',
'database' => 'database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'dbdebug' => FALSE,
'cacheon' => FALSE,
'cachedir' => '',
'charset' => 'utf8',
'dbcollat' => 'utf8generalci',
'swappre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'savequeries' => TRUE
);

目前 Droplet 2 上的应用程序无法连接到 运行 Droplet 1 上的数据库。我错过了什么?

几个问题:

编辑 运行 netstat -nltp 给出

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 :::25                   :::*                    LISTEN      -               
tcp6       0      0 :::443                  :::*                    LISTEN      -               
tcp6       0      0 :::80                   :::*                    LISTEN      -     

确保您的 my.cnf 文件中有正确的绑定地址。

bind-address                   = << private IP here >>

注意,MySQL 仅支持绑定到您服务器上的 0、1 或所有 IP 地址,因此如果您不想监听私有 IP 和 public IP,那么您将必须在 Droplet 上使用私有 IP 和 PHP 应用程序的设置来连接到它,而不是 127.0.0.1