MySQL 工作台错误 1064 [英] MySQL Workbench Error 1064

查看:87
本文介绍了MySQL 工作台错误 1064的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家!我是 MySQL 的新手.我使用 Workbench 工具创建了一个新模型(我的意思是,我自己没有编写任何代码字符串).在尝试对其进行正向工程时,我得到:

everyone! I'm newbie to MySQL. I've created a new model using Workbench tools(I mean, that I haven't written any string of code by myself). When trying to forward engineer it I get:

Executing SQL script in server
ERROR: Error 1064: 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 'COMMENT '')
ENGINE = InnoDB' at line 8
SQL Code:
    -- -----------------------------------------------------
    -- Table `university`.`CITY`
    -- -----------------------------------------------------
    CREATE TABLE IF NOT EXISTS `university`.`CITY` (
      `ID_CITY` INT NOT NULL COMMENT '',
      `CNAME` TEXT(15) NULL COMMENT '',
      `POPULATION` INT NULL COMMENT '',
      PRIMARY KEY (`ID_CITY`)  COMMENT '')
    ENGINE = InnoDB

SQL script execution finished: statements: 5 succeeded, 1 failed

 Fetching back view definitions in final form.
 Nothing to fetch

此外,在尝试转发工程师默认工作台模型sakila_full"时,我得到同样的结果:

Moreover, when trying to forward engineer default Workbench model "sakila_full" i get the same thing:

Executing SQL script in server
ERROR: Error 1064: 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 'COMMENT '',
INDEX `idx_actor_last_name` (`last_name` ASC)  COMMENT '')
ENGINE ' at line 9
SQL Code:
    -- -----------------------------------------------------
    -- Table `sakila`.`actor`
    -- -----------------------------------------------------
    CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
      `actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
      `first_name` VARCHAR(45) NOT NULL COMMENT '',
      `last_name` VARCHAR(45) NOT NULL COMMENT '',
      `last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
      PRIMARY KEY (`actor_id`)  COMMENT '',
      INDEX `idx_actor_last_name` (`last_name` ASC)  COMMENT '')
    ENGINE = InnoDB
    DEFAULT CHARACTER SET = utf8

 SQL script execution finished: statements: 5 succeeded, 1 failed

 Fetching back view definitions in final form.
Could not get definition for sakila.customer_list from server
Could not get definition for sakila.film_list from server
Could not get definition for sakila.nicer_but_slower_film_list from server
Could not get definition for sakila.staff_list from server
Could not get definition for sakila.sales_by_store from server
Could not get definition for sakila.sales_by_film_category from server
Could not get definition for sakila.actor_info from server
7 views were read back.

提前致谢!

推荐答案

看起来您对 COMMENT 字符串的理解有点过头了.根据MySQL CREATE TABLE 语法COMMENT 属性只允许在列定义中使用.这意味着它对您在 CREATE 语句末尾附近列出的 INDEXPRIMARY KEY 定义无效.

It looks like you've taken the COMMENT strings a little too far. According to the MySQL CREATE TABLE syntax, a COMMENT attribute is only permitted on a column definition. That means it's invalid on the INDEX or PRIMARY KEY definitions you have listed near the end of your CREATE statements.

COMMENT '' 不是必需的,可以完全省略,特别是因为您将它们留空.否则,它们将用于列定义中的一些额外的人类可读元数据.

The COMMENT '' aren't necessary and can be omitted entirely, especially since you are leaving them blank. Otherwise, they would be used for a little bit of extra human-readable metadata on your column definitions.

要使用您拥有的内容进行此操作,请从索引和主键定义中删除 COMMENT 属性.

To get this working with what you have, remove the COMMENT attributes from your index and primary key definitions.

CREATE TABLE IF NOT EXISTS `university`.`CITY` (
  `ID_CITY` INT NOT NULL COMMENT '',
  `CNAME` TEXT(15) NULL COMMENT '',
  `POPULATION` INT NULL COMMENT '',
  -- No COMMENT on PK
  PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `sakila`.`actor` (
  `actor_id` SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '',
  `first_name` VARCHAR(45) NOT NULL COMMENT '',
  `last_name` VARCHAR(45) NOT NULL COMMENT '',
  `last_update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
  -- No COMMENT on PK or INDEX
  PRIMARY KEY (`actor_id`),
  INDEX `idx_actor_last_name` (`last_name` ASC)
) ENGINE = InnoDB
  DEFAULT CHARACTER SET = utf8;

或者没有任何空白COMMENTs:

CREATE TABLE IF NOT EXISTS `university`.`CITY` (
  `ID_CITY` INT NOT NULL COMMENT 'A comment that is not blank!',
  `CNAME` TEXT(15) NULL,
  `POPULATION` INT NULL,
  PRIMARY KEY (`ID_CITY`)
) ENGINE = InnoDB;

(其他表相同)

MySQL 通常非常擅长通过错误消息直接指出语法错误的来源:

MySQL is generally quite good at pointing you directly to the source of your syntax error with the error message:

检查与您的 MySQL 服务器版本相对应的手册,以获取在COMMENT"附近使用的正确语法),

check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT ''),

除了在语句末尾发生的错误,这会有点含糊不清,使用near 的正确语法 将准确地告诉您错误的地方.在上面的例子中,COMMENT '') 应该引导你到唯一的 COMMENT 属性后跟一个 ),这是 )代码>主键.从那里,检查手册(上面的链接)以了解您声明的每个部分中的合法语法.

With the exception of errors occurring at the end of the statement, which get a little ambiguous, the right syntax to use near will show you exactly what's amiss. In the above case, the COMMENT '') should direct you to the only COMMENT attribute followed by a ), which was the one at PRIMARY KEY. From there, check the manual (linked above) for legal syntax in each segment of your statement.

这篇关于MySQL 工作台错误 1064的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆