0

I have created a ubuntu ec2 instance in AWS and installed the MySQL server. I've associated the instance with an elastic IP. I'm able to access the MySQL server with this address http://x.x.xxx.xx/phpmyadmin x.x.xxx.xx is my public elastic IP address. I want to access the MySQL database with my local Java application.

This is my java code

 conn = DriverManager.getConnection("jdbc:mysql://ec2-x-x-xxx-xx.ap-south-1.compute.amazonaws.com:3306/userDB",
                      "root", "password");

I'm getting a "Communications link failure due to underlying exception" error.

halfer
  • 19,824
  • 17
  • 99
  • 186
Anjana
  • 366
  • 5
  • 21
  • Java's extremely verbose exception trace back will show you the underlying exception that caused the communication failure. It's probably a timeout, but that's a guess. Try connecting to MySql on that VM with an interactive client like HeidiSQL or the mysql command-line client to troubleshoot: Java exceptions are real painful as troubleshooting tools. – O. Jones Mar 27 '21 at 11:56

1 Answers1

0

The code looks right.

Check that the security group of your ec2 allows 3306 outbound and the security group of your database allows 3306 inbound. If they are in different subnets you might have to check the NACLs as well.

David Webster
  • 2,208
  • 1
  • 16
  • 27
  • Hi David, I've checked the security ports, it is open. I can able to connect to the MySQL server using MySQL workbench from my local machine. But still getting communication error when I try to access it from local java application – Anjana Mar 27 '21 at 17:31