简体   繁体   English

无法从Springboot 1.5.9版本连接到mysql RDS

[英]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.

相关问题 无法从 SpringBoot 连接到 MySQL 数据库 - Unable to connect to MySQL database from SpringBoot 在 AWS-EC2 上运行的 SpringBoot 应用程序无法连接到 MySQL AWS-RDS 数据库 - SpringBoot app running on AWS-EC2 unable to connect to MySQL AWS-RDS database 如何从部署在PCF上的springboot应用程序连接到Amazon RDS MySQL数据库? - How to connect to Amazon RDS MySQL database from an springboot applicaiton deployed on PCF? 无法使用springboot连接到MySQL数据库? - Unable to connect to MySQL database using springboot? 无法从Elastic Beanstalk上的Java应用程序连接到MySQL Amazon RDS,java.sql.SQLException:没有合适的驱动程序 - Unable to connect to MySQL Amazon RDS from Java app on Elastic Beanstalk, java.sql.SQLException: No suitable driver 不可能从 AWS Lambda 连接到 RDS MySQL - Impossible connect to RDS MySQL from AWS Lambda 想从Docker运行mysql和springboot连接 - Want to run mysql from Docker and connect with springboot 无法从 pgadmin4 连接到 AWS RDS postgres 实例 - unable to connect to AWS RDS postgres instance from pgadmin4 当我将 SpringBoot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 SpringBoot 连接到 RDS 时出现 502 bad gateway - 502 bad gateway when I deploy SpringBoot application to AWS Elastic Beanstalk and cannot connect to RDS from local SpringBoot 无法从AWS Lambda连接到AWS RDS MySql DB。 ClassNotFoundException:com.mysql.jdbc - Not able to connect to AWS RDS MySql DB from AWS Lambda. ClassNotFoundException: com.mysql.jdbc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM