diyoda_
diyoda_

Reputation: 5420

Connecting to Database From EC2 to Another Database

I am new to AWS. I have created a Spring Web app and a database(MySql) in a EC2 instance (which is working fine). In my web application, I am connecting to a database that is in another server to read and write to this other database.

So, This database is not a MYSQL database. The network admin has opened up the port 3306 for this EC2 instance to access the database from EC2. So, the problem is in my end.

I have opened up the 3306 port (My SQL) in the security group. But when I telnet the port, the connection fails. I can see that in EC2 127.0.0.1:3306 is listening just like 80.

  1. So my question is, what am I missing here?

  2. What are the options to trouble shoot this issue?

  3. Do I have to authorize the tomcat user or Bitnami user to access ports to connect to an outer database?

Anything relevant to this issue would be helpful

thanks in advance :)

Upvotes: 0

Views: 332

Answers (3)

diyoda_
diyoda_

Reputation: 5420

It seems, This question is stupid, But then, This was a real problem. So, I will summarize what I learned and answer the question. IP Addresses are categorized into types, minimize the exhaustion of IP addresses (That is why we moved from IPV4 to IPV6). Anyways, there are Public IP addresses and Private IP addresses. Private IP addresses are for local networks and Public IP addresses are for accessing through the internet. So, What I did was, I opened up the port for the connecting Servers public IP address (It turned out to be PORT is not 3306, It was 2001 in my case, You only have to do it through Security Groups because my default all the outbound ports are open for EC2) and also, from the other end TCT PORT was opened for EC2. To do that I had to create a Elastic IP address for my EC2 (What Elastic IP address do is, it assigns a Public IP address that will not change when EC2 get restarted or changed). Then it should connect, For me it did not work till I created the Elastic IP

Upvotes: 0

Krishan Babbar
Krishan Babbar

Reputation: 798

I think you need to give permissions to user like "[email protected]" where IP is the IP from dbuser is trying to access the database.

Krish

Upvotes: 0

at0mzk
at0mzk

Reputation: 1942

If its listening on 127.0.0.1:3306 it is listening locally only and is not accessible form outside. If you change that to 0.0.0.0:3306 make sure your security groups are configured to only allow access to your database from your own instances. Dont just "open up 3306", open up 3306 only to the same security group or the security group your application spring server is in.

You say its not a mysql db, yet it uses mysql default port 3306. Thats a bit confusing. If its mysql you need to change the bind-address in my.cnf.

Upvotes: 1

Related Questions