2

I'm developing a simple web application with spring boot. In the first step, I implemented everything about the page itself and a simple login. Additionally, I implemented a database access using mysql and hibernate. My database runs on a local easyphp devserver.

In the first step, everything worked fine. However, after a reset of the database and recreating the user with the same credentials, Hibernate is not able to get a connection:

2018-02-09 21:17:11.487 ERROR 9592 --- [  restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'db'

As I can understand, no username was configured. But in my application.properties, a username is set:

spring.datasource.url=jdbc:mysql://localhost:3306/db?userSSL=false
spring.datasource.username=user
spring.datasource.password=

The exception occurres on startup, so it has to be the configuration. At the database, the user 'user' has all priviliges at the database 'db', but no one on others.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Eric
  • 123
  • 1
  • 10
  • u say that ur database is running on local easyphp devserver but u have datasource.url setup as mysql:// . can u check that ? – user641887 Feb 09 '18 at 20:47
  • Thanks for your comment @user641887. I don't think that the connection is the problem. As you can see in the error log a connection is active but the access is denied. Furthermore the database access worked with the same config previously. – Eric Feb 09 '18 at 22:31
  • can u paste your full code ? – user641887 Feb 09 '18 at 23:07
  • Maybe you have multiple application.property files for some reason and updated only one of them? Or you change the value in the property file and didn't actually save it? You could also try `mvn clean` and see if that helps... – StefanR Feb 10 '18 at 08:12
  • @user641887 properties, log or java code? – Eric Feb 10 '18 at 09:51
  • @StefanR I found one in the bin folder, but it's the same one as I edited. I'm building with Gradle so I performed a refresh and a Project > Clean but the result is still the same. – Eric Feb 10 '18 at 09:52
  • Bin folder? I don't have experience on gradle, but I think application.properties file should be in src/main/resources folder to work correctly. – StefanR Feb 11 '18 at 10:42
  • Yes it is but a dublicate is stored in the bin folder. However, both are the same, so that's not the reason unfortunatly. – Eric Feb 11 '18 at 19:13

2 Answers2

0

The data source URL might be causing the issue. Is that a typo? Can you check by resetting it to the following? It has to be "useSSL" instead of "userSSL"

spring.datasource.url=jdbc:mysql://localhost:3306/db?useSSL=false
spring.datasource.username=user
spring.datasource.password=

If the above does not work, your problem might be related to permissions for the user. A question posted here relates to yours (although it is in PHP).

Hopefully this resolves it, let us know.

Rahul Kargwal
  • 487
  • 1
  • 5
  • 20
  • Thanks for your answer. The user has all privileges on the table 'db' except grant. Unfortunatly the typo correction didn't solve the problem. – Eric Feb 09 '18 at 22:36
0

Ok, found the solution by myself. The real username contained a '_' like 'user_name'. Somehow this character was the problem why the username was not read.

Edit: Worked a few times, but the problem still exists...

Eric
  • 123
  • 1
  • 10