错误:在 Spring Boot 中使用 mysql 的用户“root”@“localhost”(使用密码:YES)的访问被拒绝

Error: Access denied for user 'root'@'localhost' (using password: YES) using mysql in Spring Boot

提问人:Anonymous 提问时间:7/21/2023 最后编辑:Anonymous 更新时间:7/21/2023 访问量:76

问:

我正在使用mysql数据库依赖项创建Spring Boot应用程序,但是出现错误:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

我在下面包含了我的 pom.xml 和 application.properties 文件:

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/AssignmentSubApp_DB
spring.datasource.username=root
spring.datasource.password= password123

spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
#spring.jpa.hibernate.ddl-auto=update

以上是我选择的application.properties设置,我不太确定这些是否是错误的原因。我尝试更改,但是错误仍然存在。

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>3.1.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.AssignmentApp</groupId>
    <artifactId>AssignmentSubmission</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>AssignmentSubmission</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</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-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-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>

Java MySQL spring-boot 错误处理 断点

评论

1赞 Tr1monster 7/21/2023
您的PW前面有一个空白区域。我不确定这是否会引起您的麻烦。

答: 暂无答案