无法连接到AWS中的mysql

时间:2017-10-09 15:35:10

标签: mysql jpa spring-boot

当我在AWS EC2实例中运行jar时,我的spring启动应用程序抛出错误。当我在本地系统中运行时,它工作正常。

我的application.properties文件是

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/gbi?    useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=fa    lse&serverTimezone=UTC&autoReconnect=true&failOverReadOnly=false&maxReconne    cts=10
spring.jpa.database-platform =org.hibernate.dialect.MySQLDialect
spring.datasource.username=******
spring.datasource.password=******@
spring.datasource.pool.size=20
spring.jpa.hibernate.ddl-auto=update
server.port=8090

当我在AWS服务器中运行jar时,出现以下错误

 Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 
Could not create connection to database server. Attempted reconnect 10 
times. Giving up.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

接着,

Caused by: 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)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

接着,

Caused by: java.net.ConnectException: Connection refused (Connection 
refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
atjava.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

接着,

2017-Oct-09 15:24:49.735 WARN  [main] o.s.b.a.o.j.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.MySQLNonTransientConnectionException: 
Could not create connection to database server. Attempted reconnect 10 
times. Giving up.

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

获取Ec2并单击安全组,然后在底部添加一个新的安全组,类型为MYSQL / Aurora protocal作为TCP并选择端口号,然后在源代码中选择您的计算机的IP地址。 您应该能够解决您的问题。

谢谢, 马杜