将AWS EC2 mysql与我的本地Java应用程序连接 [英] Connect aws ec2 mysql with my local java application

查看:45
本文介绍了将AWS EC2 mysql与我的本地Java应用程序连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在AWS中创建了一个ubuntu ec2实例并安装了MySQL服务器.我已将实例与弹性IP相关联.我可以使用以下地址访问MySQL服务器: http://x.x.xxx.xx/phpmyadmin x.x.xxx.xx是我的公共弹性IP地址.我想使用本地Java应用程序访问MySQL数据库.

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.

这是我的Java代码

 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.

推荐答案

代码看起来正确.

检查ec2的安全组是否允许3306出站,数据库的安全组是否允许3306入站.如果它们位于不同的子网中,则可能还必须检查NACL.

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.

这篇关于将AWS EC2 mysql与我的本地Java应用程序连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆