简体   繁体   English

如何远程连接到私有 EC2 实例中的 MySQL 数据库到本地主机中的 Visual Studio

[英]How to remotely connect to MySQL database which is in Private EC2 instance to Visual Studio in localhost

I have created 2 EC2 instance one is public which has public IP and private IP and other one is private instance which has only private IP.我创建了 2 个 EC2 实例,一个是公共的,它具有公共 IP 和私有 IP,另一个是私有实例,它只有私有 IP。 Only public instance can access private instance and private instance contains MYSQL database.只有公共实例可以访问私有实例,私有实例包含 MYSQL 数据库。 Public instance contain webserver which I publish from local pc.公共实例包含我从本地电脑发布的网络服务器。 I want to know how to access to database which is in my private instance to my ASP.net project so I can establish SQL connection我想知道如何访问我的私有实例中的数据库到我的 ASP.net 项目,这样我就可以建立 SQL 连接

You could run a port redirector software on the publicly accessible instance, to redirect traffic to the private instance, then open up the public instance's firewall to accept traffic from your IP only, to the port redirector port您可以在可公开访问的实例上运行端口重定向器软件,将流量重定向到私有实例,然后打开公共实例的防火墙以仅接受来自 IP 的流量到端口重定向器端口

Or, use something like ngrok on the private instance to funnel traffic through their proxies and make it like MySQL is running on your machine或者,在私有实例上使用 ngrok 之类的东西来通过他们的代理汇集流量,并使其就像 MySQL 在您的计算机上运行一样

Or install MySQL studio software on the public instance and access it via RDP或者在公共实例上安装MySQL studio软件,通过RDP访问

But for all the messing around it is, I'd just give the private instance a public ip address, lock it down to being accessible to your IP only and use it directly但是对于所有的混乱情况,我只是给私有实例一个公共 ip 地址,将其锁定为只能由您的 IP 访问并直接使用它

The common way to access a private instance, rds or any other resource in a VPC from your local workstation is through ssh tunnel .从本地工作站访问私有实例、rds 或 VPC 中任何其他资源的常用方法是通过ssh 隧道

So basically, you would establish ssh tunnel to a public instance , which would then forward connections to the private instance with mysql.所以基本上,您将建立 ssh 隧道到公共实例,然后将连接转发到具有 mysql 的私有实例。 Having the tunnel, you would access your database using localhost on your local workstation.有了隧道,您将使用本地工作站上的localhost访问您的数据库。

There is a number of tutorials on how to do it.有许多关于如何做到这一点的教程。 Examples are:例子是:

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

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