Error spring boot when connecting to mysql

Asked

Viewed 3,037 times

1

I created a test project by Spring Tool Suite to create a REST server that will connect with a local mysql database, when I start the application it error when trying to connect with mysql: java.sql.Sqlexception: Access denied for user ''@'localhost' (using password: NO)

I find it strange that he didn’t try with the root user I set up in the project.

The application.properties is thus:

spring.jpa.show-sql=true
spring.jpa.database=mysql

spring.datasource.url=jdbc:mysql://localhost/users
spring.datasource.data-username=root
spring.datasource.data-password=12345
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

And pom.xml is like this:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

In the database I executed the following command:

GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '12345';

After running I stopped and started mysql.

From what I understand, this root access command on all tables and from anywhere.

I find it strange that in the error it appears '@'localhost 'instead of root.

Is it the connection config. that is wrong, the pom.xml or the database ?

1 answer

2


Can you send the directory tree that is being used? How are you doing to execute? The error "(using password: NO)" means that Spring Boot failed to reflect to your Properties file settings.

Make sure the Properties file directory is /project/src/main/Resources/application.properties

Also your properties are not correct. Use: spring.datasource.username = root spring.datasource.password = 12345

Example: https://github.com/netgloo/spring-boot-samples/blob/master/spring-boot-mysql-springdatajpa-hibernate/src/main/resources/application.properties

:D

  • 1

    The problem was in the configuration: spring.datasource.username = root spring.datasource.password = 12345 Put this and solved! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.