After creating MySQL database on AWS RDS, you need to the following setup to connect to the RDS database:
Step 1: Update the Security Group inbound rule for the MySQL database to allow connection from the machine which will connect to the DB. In the following example, we setup the connection open to only one EC2 machine.
If EC2 instance is in the same virtual private network. Then you can use ifconfig to find the EC2 instance's private IP address and enable it's access to the MySQL database:
Step 1: Update the Security Group inbound rule for the MySQL database to allow connection from the machine which will connect to the DB. In the following example, we setup the connection open to only one EC2 machine.
If EC2 instance is in the same virtual private network. Then you can use ifconfig to find the EC2 instance's private IP address and enable it's access to the MySQL database:
[ec2-user@ip-172-30-0-198 ~]$ ifconfig eth0 Link encap:Ethernet HWaddr 0E:98:20:75:FD:F7 inet addr:172.30.0.198 Bcast:172.30.0.255 Mask:255.255.255.0 inet6 addr: fe80::c98:20ff:fe75:fdf7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1 RX packets:115738 errors:0 dropped:0 overruns:0 frame:0 TX packets:54608 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:163814586 (156.2 MiB) TX bytes:3842654 (3.6 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:2 errors:0 dropped:0 overruns:0 frame:0 TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:140 (140.0 b) TX bytes:140 (140.0 b)
If the EC2 instance is in a different virtual private network, you then need to use the Public IP address. You can find the Public IP address of EC2 instance in "IPv4/IPV6 Public IP" attributes.
Step 2: Connect to the MySQL RDS instance with the endpoint information.
The following is an example:
The following is an example:
[ec2-user@ip-172-30-0-198 ~]$ mysql -h aws-mysql-master.cserhpfzdaax.us-east-1.rds.amazonaws.com -P 3306 -u jinyu -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 94 Server version: 5.6.27-log MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
For the on-premises connection, it follows the same rule.
Created: 3/16/2016, Last Updated: 7/12/2017