MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use'

MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use'

实际上,我正在使用 Spring 启动,在数据库中创建 table 时出错。我正在使用 MySQL 作为我的数据库

错误是

在 Spring 引导中显示错误

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like bigint not null, time_created time, primary key (blog_id)) engine=InnoDB' at line 1

尝试手动创建 table

时出错
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like bigint not null, time_created time, primary key (blog_id)) engine=InnoDB' at line 1

我的命令

create table blogs (blog_id integer not null, date_created date, discription varchar(999), dislike bigint not null, like bigint not null, time_created time, primary key (blog_id)) engine=InnoDB;

和我的实体

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int blogId;

@Column(length = 999)
private String discription;

@CreatedDate
private LocalDate dateCreated;

private LocalTime timeCreated;
private long like;
private long dislike;


public blogs(int blogId, String discription, LocalDate dateCreated, LocalTime timeCreated, long like,
        long dislike) {
    this.blogId = blogId;
    this.discription = discription;
    this.dateCreated = dateCreated;
    this.timeCreated = timeCreated;
    this.like = like;
    this.dislike = dislike;
}

错误在于您的 SQL 声明。 LIKE 是一个 keyword/reserved 词,不能用作属性名称。

将 SQL blogs table 创作的声明更改为以下内容:

CREATE TABLE blogs (
    blog_id        integer        not null, 
    date_created   date, 
    discription    varchar(999), 
    dislike        bigint         not null, 
    liked          bigint         not null, 
    time_created   time, 
    primary key (blog_id)
) engine=InnoDB;

我遇到了与 read 类似的问题。我没有更改属性名称,而是用两个反引号 (`).

包围了 read

改变

private long like;

@Column(name = "`like`")
private long like;