Reputation: 7581
After reading and trying the answers of similar posts, I do want to ask this question. Has my issue to do with migrating to spring boot 2.0.0?
After creating any MySql database, locally or RDS AWS, I cannot get my Spring Boot 2.0.0 application connected to it. I still see that the exception: ... Access denied for user ... (using password: YES).
IMPORTANT: With the following simple Java program I could !! access the AWS RDS MySql database. I could also create tables, etc.
Class.forName("com.mysql.jdbc.Driver");
// Username and password created via MySQL workbench
String username = "dbuser";
String password = "dbpassword";
String jdbcUrl = "jdbc:mysql://myhostname:3306/mydatabase?user=" + username + "&password=" + password;
Connection con = DriverManager.getConnection(jdbcUrl);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(selectStmt);
With a simple Spring Boot 2.0.0 application, I cannot get connected. First I get this error:
2018-12-25 10:36:59.670 ERROR 7184 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.sql.SQLException: Access denied for user 'dbuser'@'dhcp-etc' (using password: YES)
Further down I get this error:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by:
org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution Caused by: java.sql.SQLException: Access denied for user 'dbsetup'@'dhcp-ipaddress-etc-.nl' (using password: YES)
And:
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'dbuser'@'dhcp-etc' (using password: YES)
This is my application.properties file:
spring.datasource.url=jdbc:mysql://myhostname:3306/mydatabase
spring.datasource.username=dbuser
spring.datasource.password=dbpassword
#REMOVED: spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
Using this addition to the connection string does not have any effect: ?useSSL=false
My pom.xml contains:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
// anything related to databases:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
// I also tried version 5.1.40
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version> <!-- without this version, same results -->
</dependency>
After connecting correctly from my PC (with Spring Boot) I will continue to develop with an EC2 instance.
AWS RDS MySQL version: 5.6.41.
Upvotes: 0
Views: 2084
Reputation: 1
Check your application.properties file carefully, there should not be any space after your DB username or password.
or, you can write in this way :
spring.datasource.url=jdbc:mysql://localhost:3306/dbname?user=dbuser&password=dbpassword
Upvotes: 0
Reputation: 6254
Let parent load its compatible mysql connector lib so try without version..
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Upvotes: 1