简体   繁体   中英

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). I've installed php, apache and mysql in that instance as well and I have a question about it. There is a.pem file which is used as a password when i connect to the instance. If i want to connect to the instance through Visual studio, How can i get the password? I mean, In an API function, to connect to database requires the password of the server. However, EC2 instance has.pem file as a password so how could i retrieve.pem file as a real password? (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 @.@???? Thanks in advance indeed!

Visual Studio Integration

One way to do it is to download the Connector/Net driver for MySQL and install it. Then in your Web.config file add a connection string similar to the below to connect to the database. Then setup your models to reflect the tables in your MySQL database. Create a DbContext class with the same name as the connection string name in your Web.config file. 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

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.Select to have the CRUD create via Template. Doing so will create the basic Create, Read, Update, and Delete controller actions and views for you.

You don't need.pem file to connect to database through VS. .pem file is needed when you try to SSH into the instance. For connecting to MySQl DB, MySQL host,user and password are required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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