繁体   English   中英

在 MYSQL 工作台、spring 引导中看不到 MYSQL 表信息

[英]Can't see MYSQL table information in MYSQL workbench, spring Boot

我正在尝试将我的 spring 引导应用程序连接到 MYSQL 工作台,但我在 MYSQL 工作台中找不到我的任何列。

我的设置:这个 application.properties 文件

spring.datasource.url=jdbc:mysql://localhost:3306/blog?useUnicode=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true

当我尝试不使用“?useUnicode=true&useLegacyDatetimeCode=false&serverTimezone=UTC”时,出现以下错误

HHH000342: Could not obtain connection to query metadata : The server time zone value 'EDT' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specifc time zone value if you want to utilize time zone support.

我的 Maven 依赖项

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.blogportfolio</groupId>
    <artifactId>blog</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Bala's Blog</name>
    <description>Blog portfolio backend</description>

    <properties>
        <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>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

文章 Class

package com.blogbackend.Model;

import com.sun.istack.NotNull;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;


@Entity
@Getter
@Setter
@Table (name = "Articles")
public class Article {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private int id;

    @NotNull
    @Column(name="articleName")
    private String artName;

    @NotNull
    @Column(name="articleBody")
    private String artBody;

    @NotNull
    @Column(name="articleCategory")
    private String artCategory;

    @NotNull
    @Column(name="articleCreated")
    private Date artCreated;

    @Column
    private Author author;

    public Article(int id) {
        this.id = id;
    }
}

当我 go 到 WorkBench 时,博客架构为空。 在此处输入图像描述

据我所知,它与您要使用的架构/表无关,而更像是服务器配置问题。 根据这一点,它带有特定版本的使用驱动程序,必须设置此属性。

为了完成所需表的自动创建, 可能会有所帮助。

如果在应用程序运行时创建已经成功,只需将ddl-auto参数从

spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.hibernate.ddl-auto=create

并且一旦创建更改以validateupdate

进一步的解释可以在这里找到。

您的Article实体的身份生成策略是GenerationType.SEQUENCE 但是MySQL不直接支持Sequence

这就是为什么当spring.jpa.hibernate.ddl-auto=create-drop尝试创建模式时失败的原因。

AUTO_INCREMENTGenerationType.IDENTITY一起使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM