skip to Main Content

So as the title says I can’t connect to my database through spring-boot the database seems to be working fine in PHPMyAdmin and in the workbench in PHPMyAdmin I checked the user setting and user root has all privileges enabled I’m guessing its something with MySQL I’m using MySQL 8. This Is a school project so I’m not really sure where the problem is any help would be appreciated

the error log

  java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.22.jar:8.0.22]
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.22.jar:8.0.22]
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.22.jar:8.0.22]
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.22.jar:8.0.22]
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.22.jar:8.0.22]

the application properties

    spring.datasource.url= jdbc:mysql://localhost:3306/cardb
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
    spring.datasource.data-username=root
    spring.datasource.data-password=09130425
    spring.jpa.hibernate.ddl-auto=update

the pom xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

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

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


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

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

</project>

3

Answers


  1. try to run off ssl to your local mysql database

    spring.datasource.url= jdbc:mysql://localhost:3306/cardb?autoReconnect=true&useSSL=false
    
    Login or Signup to reply.
  2. Try to update your application.properties file

    spring.datasource.url=jdbc:mysql://localhost:3306/cardb  
    spring.datasource.data.username=root
    spring.datasource.dat.password=09130425
    spring.jpa.hibernate.ddl-auto=update
    
    Login or Signup to reply.
  3. spring.datasource.url= jdbc:mysql://localhost:3306/cardb
    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
    spring.datasource.data.username=root
    spring.datasource.data.password=09130425
    spring.jpa.hibernate.ddl-auto=update
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search