How to connect AWS RDS with MySQL Workbench application.
Published: 2022-08-20 14:20:18

## **What is AWS RDS?**

> Amazon RDS is a Relational Database Cloud Service.
> Amazon RDS creates multiple instances for high availability and failovers.
> Amazon RDS supports PostgreSQL, MySQL, Maria DB, Oracle, SQL Server, and Amazon Aurora.

**Note**

> - RDS should always be configure inside a private subnet as because its a Database.
> - Backup retention is very easy in case of RDS.
> - RDS has an endpoint through which we can able to connect it with mysql workbench. 

**_QS)-Now the question is how to connect AWS RDS which is present inside a private subnet of VPC from our local computer application [ MYSQL Workbench ]?_**

- Ans:- One of the way is through OpenVpn setup. Once we able to setup an OpenVpn network , We can associate Host name ,port,Username,Password of RDS to our MYSQL workbench and able to connect.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5158qauiqrnnhdpnlqfg.png)

## **LAB WORK**


**RDS setup**
1. Create a VPC. [CIDR range :- 10.0.0.0/16]

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/md91apolu2yq3cvoh29z.png)

2. Create two Private subnet with subnet association inside that VPC [ Atleast 2AZ] .Ipv4 CIDR:- 10.0.2.0/24 and 10.0.4.0/24

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ks4ksx0l99p7afii3mm1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mbf51tfpxnjuvkn8531g.png)

3. Create subnet groups and attach all subnet present inside that VPC.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sneir7qqday37h9d9dg.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75u3tnt1656h91cua82i.png)

4. Launch a RDS inside those private subnet.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yptp4575w3wszrv0axtj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/agmlvmqk855taba61m59.png)

-Create username and password.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbrwzwwqfkdwu483w8uo.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fb7e2j9oynpwc8ypodar.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ja687hqhfhtbq9esabfu.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zk95uq6pwulqeq551ows.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zel3ulyfydcpndp7bc5h.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4y8e5v7n47n0furxhv3.png)
-Copy the endpoints and attach it in Mysql workbench host name.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rp51ggpyyslkqgmj7pd.png)


**OpenVpn Setup**


1. Create an Internet Gateway attach it with that VPC.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nsq32m80dhbzw21wz3sr.png)

2. Create One public subnet with subnet association and routes table associated with internet gateway.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bost66ek8l6zbhg66fqi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rveppxlm0bn1srlndu1z.png)

3. Deploy an OpenVpn in the Public subnet and connect it through xshell.
-launch configuration.
- Search for Openvpn.
- Select OpenVpn Access server and launch it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwfb20bi6fc7u4n23n8e.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gmevg5tbhfuidabeqqoz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccf2x3fqh19mc3ds7tbk.png)

4. Install OpenVpn ,set the username and password and get the admin and client url for further use.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ah80v7f0rrl8asnt6hix.png)

-Change the password.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnfjikad0o9a8k30nh3w.png)

- Copy and paste the admin and client url for further use.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9807apev1ktd38jmxhc.png)

-Go to openvpn application and paste client url.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jw4rfg3fv6ygmexhqa1h.png)

-Enter your username and password and connect.
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7d82z1rp3em6ezchzfr.png)
-Now turn on VPN.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bsfymkjtlud8ma3qtu3m.png)

> - Download and install MySQL Workbench.
> - Open MySQL Workbench, and choose the ⊕ sign beside MySQL Connections to set up a new connection.
> - In the Setup New Connection dialog box, enter a suitable name for your connection.
> - In the Parameters section, enter the following details:
> - Host name: Enter the RDS endpoint
> - Port: Enter Port the number
> - Username: Enter the master user


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/26rlj14bb457io5dncwr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnnmatf1txyvlkb6cyy3.png)

> - Choose Test Connection.
> - In the popup that appears, enter the password that you configured when you created the DB instance, and then choose OK.
> - After testing your connection, from the Setup new connection dialog box, choose OK to save the connection.
-Now You have successfully connected to Aws rds.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d9k1jnf4igcfi690tfi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rml3cs27i5yx1ak29gmf.png)