java - AWS RDS 连接数据库错误 : com. mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

标签 java mysql amazon-web-services spring-boot

我正在尝试在 AWS linux 实例上部署我的 springboot 应用程序,但是我不断收到以下错误:

2018-04-24 18:15:27.777  INFO 24020 --- [ost-startStop-1] 

o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-04-24 18:15:28.771 ERROR 24020 --- [main] o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]

... 

2018-04-24 16:58:57.522  WARN 23780 --- [main] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasource

org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: 
Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

这就是我创建 applications.properties 文件的方式:

#database config
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://****-west-1.rds.amazonaws.com:3306/DevManagementDB
spring.datasource.username=root
spring.datasource.password=mypassword
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update

奇怪的是,当我在本地机器上运行应用程序时,我可以从这个 springboot 应用程序连接到我的 RDS 数据库。一旦我尝试将应用程序部署到 AWS 上的 linux 实例,它就会失败,并且出现上述错误。

最佳答案

如果您的数据库是 RDS 实例,请确保访问数据库的设备的公共(public) IP 地址包含在 RDS 实例的安全组中。还要确保公共(public) IP 地址包含在相应 VPC 安全组的入站 channel 中。

关于java - AWS RDS 连接数据库错误 : com. mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50008728/

相关文章:

mysql - 反向加入Django

php - 为什么这不会输出 MySQL Artist 表中的所有数据?

amazon-web-services - 不活动后自动 "stop"Sagemaker笔记本实例?

amazon-web-services - 将自定义指令添加到 AWS Beanstalk 上的 wsgi.conf

c# - 使用 Parallel.For 时出现不可预测的结果

java - IntelliJ 中的正则表达式反向引用

java - 使用 DSN 连接 SQL SEVER 时只允许有一个结果集实例

java - 无法使用 JDBC 驱动程序连接到 PostgreSQL

MacOS ARM 上的 JavaFX : Graphics Device initialization failed

java - Spring bean销毁方法