简体   繁体   English

通过基于密钥的身份验证通过PHP连接到EC2实例上的MySql

[英]Connect through PHP to MySql on EC2 instance with key-based authentication

I have an EC2 instance running a mysql server, and the server uses key-based authentication to connect to it. 我有一个运行mysql服务器的EC2实例,该服务器使用基于密钥的身份验证连接到它。 I am needing to connect to the mysql server on this EC2 instance through PHP from a different non-amazon server. 我需要通过PHP从另一台非Amazon服务器连接到此EC2实例上的mysql服务器。 Is this possible? 这可能吗? If so, how do I do this? 如果是这样,我该怎么做? Do I need to use ssh2 connection functions in PHP? 我需要在PHP中使用ssh2连接功能吗? Obviously, I can't just use mysql_connect because the server uses key-based authentication. 显然,我不能仅使用mysql_connect,因为服务器使用基于密钥的身份验证。 Any help anyone could give would be greatly appreciated. 任何人都可以提供的任何帮助将不胜感激。

I am going to assume that by key based authentication you mean ssh keys and not connecting to mysql with keys. 我将假设通过基于密钥的身份验证是指ssh密钥,而不是通过密钥连接到mysql。

So you have a couple of options. 因此,您有两种选择。

  1. Use an SSH tunnel. 使用SSH隧道。 This uses an ssh listener on your non-amzn server and forwards all communications to mysql instance via SSH. 这将在非amzn服务器上使用ssh侦听器,并通过SSH将所有通信转发到mysql实例。 This is more secure, but not without some overhead. 这样更安全,但并非没有开销。

  2. If security is less of a concern you can open your security groups to the ip of the non-amzn server and set up a connection directly to port 3306 (or whatever port you are using) 如果安全性不太重要,则可以将安全组打开到非amzn服务器的ip,并直接建立与端口3306(或您使用的任何端口)的连接

In any case, you will end up with some latency running queries like this. 无论如何,您最终都会遇到一些像这样的延迟运行查询。 Depending on the connection between your servers. 取决于服务器之间的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM