[英]Digital Ocean connect one droplet to the MySQL DB of another droplet
I have 2 droplets, both with a LAMP stack (Ubuntu 16.04). 我有2个液滴,两个液滴都带有LAMP堆栈(Ubuntu 16.04)。 Both also have PHPMyAdmin installed, run a PHP application, and have a self-signed SSH certificate that auto redirects to https. 两者均已安装PHPMyAdmin,运行PHP应用程序,并具有自动重定向到https的自签名SSH证书。
What I would like to do is connect to the MySQL database that's on Droplet 1 from the app on Droplet 2. I know you can do this by running a MySQL server on Droplet 1, but both need to run a full PHP app in this case. 我想做的是从Droplet 2上的应用程序连接到Droplet 1上的MySQL数据库。我知道您可以通过在Droplet 1上运行MySQL服务器来做到这一点,但是在这种情况下,两者都需要运行完整的PHP应用程序。
Here is what I've already done and tried: 这是我已经完成并尝试的操作:
sudo ufw allow 3306/tcp
and sudo service ufw restart
在Droplet 1上,我已使用sudo ufw allow 3306/tcp
将端口3306添加到防火墙, sudo ufw allow 3306/tcp
和sudo service ufw restart
My PHP app connection settings (CodeIgniter 3.1.7) 我的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
);
Currently the app on Droplet 2 can not connect to the database that runs on Droplet 1. What am I missing? 当前,Droplet 2上的应用程序无法连接到在Droplet 1上运行的数据库。我缺少什么?
A few questions: 几个问题:
mysql_secure_installation
. 当安装两个mysql_secure_installation
我已经运行了mysql_secure_installation
。 If I remember correctly that disables remote access to the mysql databases, but not sure. 如果我没有记错的话,那会禁止对mysql数据库的远程访问,但是不确定。 I also don't know how to enable it again (if needed). 我也不知道如何再次启用它(如果需要)。 EDIT Running netstat -nltp
gives 编辑运行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 -
Make sure you have the correct bind address in your my.cnf
file. 确保您的my.cnf
文件中具有正确的绑定地址。
bind-address = << private IP here >>
Heads up, MySQL only supports binding to 0, 1 or all IP addresses on your server so if you don't want to listen on the private and public IP then you'll have to use the private IP and the settings of your PHP app on Droplet to connect to that instead of 127.0.0.1
. 请注意,MySQL仅支持绑定到服务器上的0、1或所有IP地址,因此,如果您不想侦听私有和公共IP,则必须使用私有IP和PHP应用程序的设置在Droplet上连接而不是127.0.0.1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.