MySQL Workbench 错误 1064
MySQL Workbench Error 1064
大家好!我是 MySQL 的新手。我使用 Workbench 工具创建了一个新模型(我的意思是,我没有自己编写任何代码串)。
当尝试正向工程时,我得到:
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
此外,在尝试转发工程师默认 Workbench 模型 "sakila_full" 时,我得到了同样的结果:
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
字符串的理解有点过头了。根据 the MySQL CREATE TABLE
syntax,COMMENT
属性只允许在列定义中使用。这意味着它对您在 CREATE
语句末尾列出的 INDEX
或 PRIMARY KEY
定义无效。
COMMENT ''
不是必需的,可以完全省略,尤其是当您将它们留空时。否则,它们将用于您的列定义中的一些额外的人类可读元数据。
要使它与您所拥有的一起使用,请从您的索引和主键定义中删除 COMMENT
属性。
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;
或者没有 any 空白的整个事情 COMMENT
s:
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;
(另一个相同table)
MySQL 通常非常擅长通过错误消息直接将您指向语法错误的来源:
check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT ''),
除了在语句末尾出现的错误会变得有点模棱两可外,使用 near 的正确语法会告诉您到底出了什么问题。在上面的例子中,COMMENT '')
应该将您引导到唯一的 COMMENT
属性,后跟 )
,这是 PRIMARY KEY
处的属性。从那里,检查手册(上面链接)以了解语句每个部分的合法语法。
嗯,最大的问题是 Mysql Workbench 在使用 "Forward Engineer" 或 "Synchronize Model"
时添加了自己的索引评论,这些评论会产生错误
我用的是6.0版本的时候不存在这个问题
从所有 INDEX 中删除“VISIBLE”和“INVISIBLE”字词
大家好!我是 MySQL 的新手。我使用 Workbench 工具创建了一个新模型(我的意思是,我没有自己编写任何代码串)。 当尝试正向工程时,我得到:
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
此外,在尝试转发工程师默认 Workbench 模型 "sakila_full" 时,我得到了同样的结果:
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
字符串的理解有点过头了。根据 the MySQL CREATE TABLE
syntax,COMMENT
属性只允许在列定义中使用。这意味着它对您在 CREATE
语句末尾列出的 INDEX
或 PRIMARY KEY
定义无效。
COMMENT ''
不是必需的,可以完全省略,尤其是当您将它们留空时。否则,它们将用于您的列定义中的一些额外的人类可读元数据。
要使它与您所拥有的一起使用,请从您的索引和主键定义中删除 COMMENT
属性。
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;
或者没有 any 空白的整个事情 COMMENT
s:
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;
(另一个相同table)
MySQL 通常非常擅长通过错误消息直接将您指向语法错误的来源:
check the manual that corresponds to your MySQL server version for the right syntax to use near 'COMMENT ''),
除了在语句末尾出现的错误会变得有点模棱两可外,使用 near 的正确语法会告诉您到底出了什么问题。在上面的例子中,COMMENT '')
应该将您引导到唯一的 COMMENT
属性,后跟 )
,这是 PRIMARY KEY
处的属性。从那里,检查手册(上面链接)以了解语句每个部分的合法语法。
嗯,最大的问题是 Mysql Workbench 在使用 "Forward Engineer" 或 "Synchronize Model"
时添加了自己的索引评论,这些评论会产生错误我用的是6.0版本的时候不存在这个问题
从所有 INDEX 中删除“VISIBLE”和“INVISIBLE”字词