[英]Unable to connect to mysql RDS from Springboot 1.5.9 version
I'm using AWS RDS mysql 5.7.23 version. 我正在使用AWS RDS mysql 5.7.23版本。 I'm trying to establish the mysql connection from a configuration class using the code below.
我正在尝试使用下面的代码从配置类建立mysql连接。
@Configuration
public class DbConnection{
private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
@Bean
public Connection getConnection() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String jdbc_url = "jdbc:mysql://myhost:3306/myDB?autoReconnect=true&useSSL=false&user=user123&password=user123";
con = DriverManager.getConnection(jdbc_url);
return con;
} catch (Exception e) {
logger.info("ERROR " + e.getMessage(), e);
}
return con;
}
}
I have set up the logging as logging.level=ERROR,INFO,DEBUG,WARN
in applications.properties file. 我已在
logging.level=ERROR,INFO,DEBUG,WARN
文件中将日志记录设置为logging.level=ERROR,INFO,DEBUG,WARN
。 When I start the springboot application its throwing exception 当我启动springboot应用程序时,它的抛出异常
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: java.sql.SQLException: Access denied for user 'user123'@'myhostIP' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3996)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2287)
I'm using the dependecy and also without any version so that springboot itself chose a version. 我使用的是Dependecy,并且也没有任何版本,因此springboot本身选择了一个版本。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
I can Connect the same instance by standalone java program using the same details. 我可以使用相同的详细信息通过独立的Java程序连接相同的实例。
Any help on this why I'm unable to connect with springboot application. 关于这个为什么我无法与springboot应用程序连接的任何帮助。
Delete your DbConfiguration
class and use Spring Boot's auto configuration https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-connect-to-production-database by adding the following to your application.properties
: 删除您的
DbConfiguration
类并使用Spring Boot的自动配置https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-connect-to-production-通过将以下内容添加到application.properties
来创建数据库 :
spring.datasource.url=jdbc:mysql://myhost/myDB
spring.datasource.username=user123
spring.datasource.password=user123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.