简体   繁体   English

如何在 Visual Studio 中连接 mysql(基于 EC2 实例)?

[英]How to connect mysql(based on EC2 instance) in Visual studio?

I am a totally new on Amazon EC2 and I have just created an AMI instance (Linux).我是 Amazon EC2 的新手,我刚刚创建了一个 AMI 实例 (Linux)。 I've installed php, apache and mysql in that instance as well and I have a question about it.我在那个实例中也安装了 php、apache 和 mysql,对此我有疑问。 There is a.pem file which is used as a password when i connect to the instance.当我连接到实例时,有一个 .pem 文件用作密码。 If i want to connect to the instance through Visual studio, How can i get the password?如果我想通过 Visual Studio 连接到实例,我如何获取密码? I mean, In an API function, to connect to database requires the password of the server.我的意思是,在 API function 中,连接到数据库需要服务器的密码。 However, EC2 instance has.pem file as a password so how could i retrieve.pem file as a real password?但是,EC2 实例有 .pem 文件作为密码,所以我如何检索 .pem 文件作为真实密码? (I want to make a program in VS and i need to connect to MySQL which is in the EC2 instance) well, basically, Is it possible to retrieve the password @.@???? (我想在 VS 中制作一个程序,我需要连接到 EC2 实例中的 MySQL)好吧,基本上,是否可以检索密码@.@???? Thanks in advance indeed!在此先感谢!

Visual Studio Integration视觉工作室集成

One way to do it is to download the Connector/Net driver for MySQL and install it.一种方法是下载 MySQL 的连接器/网络驱动程序并安装它。 Then in your Web.config file add a connection string similar to the below to connect to the database.然后在你的 Web.config 文件中添加一个类似于下面的连接字符串来连接到数据库。 Then setup your models to reflect the tables in your MySQL database.然后设置模型以反映 MySQL 数据库中的表。 Create a DbContext class with the same name as the connection string name in your Web.config file.创建一个与 Web.config 文件中的连接字符串名称同名的 DbContext class。 Then you can work with it as normal.然后你就可以正常使用它了。

<connectionStrings>
    <add name="SuperSmartDB" connectionString="server=ec2-50-34-34-157.compute-1.amazonaws.com;user=root;database=superrdb;port=3306;password=nunya123;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>

If new to Visual Studio如果不熟悉 Visual Studio

Once all your models are created you can create a new controller. When creating the controller: set model class to the table you want to work with and the data context class to the context that matches your connection sting in Web.config.创建所有模型后,您可以创建一个新的 controller。创建 controller 时:将 model class 设置为您要使用的表,将数据上下文 class 设置为与 88763685config.7905 中的连接字符串匹配的上下文Select to have the CRUD create via Template. Select 通过模板创建 CRUD。 Doing so will create the basic Create, Read, Update, and Delete controller actions and views for you.这样做将为您创建基本的创建、读取、更新和删除 controller 操作和视图。

You don't need.pem file to connect to database through VS.你不需要.pem 文件通过 VS 连接到数据库。 .pem file is needed when you try to SSH into the instance.当您尝试 SSH 进入实例时,需要 .pem 文件。 For connecting to MySQl DB, MySQL host,user and password are required.要连接到 MySQl DB,需要 MySQL 主机、用户和密码。

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

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