mysql workbench 1064,MySQL Workbench:查询错误(1064):第1行“ VISIBLE”附近的语法错误...

Any ideas why VISIBLE below is causing an issue?

CREATE TABLE IF NOT EXISTS `setting` (

`uuid` INT(10) NOT NULL,

`type` VARCHAR(255) NOT NULL,

`code` VARCHAR(255) NOT NULL COMMENT 'An unique name.',

`value` MEDIUMTEXT NULL DEFAULT NULL,

`comment` LONGTEXT NULL DEFAULT NULL,

`created_on` INT UNSIGNED NOT NULL,

`updated_on` INT UNSIGNED NOT NULL,

PRIMARY KEY (`uuid`))

ENGINE = MyISAM

DEFAULT CHARACTER SET = utf8;

CREATE UNIQUE INDEX `name_UNIQUE` ON `setting` (`code` ASC) VISIBLE;

CREATE UNIQUE INDEX `uuid_UNIQUE` ON `setting` (`uuid` ASC) VISIBLE;

Errors:

CREATE UNIQUE INDEX name_UNIQUE ON setting (code ASC) VISIBLE

Error in query (1064): Syntax error near 'VISIBLE' at line 1

CREATE UNIQUE INDEX uuid_UNIQUE ON setting (uuid ASC) VISIBLE

Error in query (1064): Syntax error near 'VISIBLE' at line 1

No error if I remove VISIBLE but MySQL Workbench 8.0.12 auto generates that. How can I stop MySQL Workbench from doing that?

My MySQL info in my Ubuntu 18.04:

MySQL version: 5.7.23-0ubuntu0.18.04.1 through PHP extension MySQLi

解决方案

The problem here is the difference in syntax across different MySQL server versions. It seems that MySQL Workbench 8.0.12 is auto-generating CREATE UNIQUE INDEX statement for the MySQL server version 8.0.

From the MySQL Server 8.0 Docs, the syntax for CREATE INDEX is:

CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name

[index_type]

ON tbl_name (key_part,...)

[index_option]

[algorithm_option | lock_option] ...

key_part: {col_name [(length)] | (expr)} [ASC | DESC]

index_option:

KEY_BLOCK_SIZE [=] value

| index_type

| WITH PARSER parser_name

| COMMENT 'string'

| {VISIBLE | INVISIBLE} /* Notice the option of VISIBLE / INVISIBLE */

index_type:

USING {BTREE | HASH}

However, this option of {VISIBLE | INVISIBLE} is not available in the MySQL Server 5.7. From Docs:

CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name

[index_type]

ON tbl_name (key_part,...)

[index_option]

[algorithm_option | lock_option] ...

key_part:

col_name [(length)] [ASC | DESC]

index_option:

KEY_BLOCK_SIZE [=] value

| index_type

| WITH PARSER parser_name

| COMMENT 'string' /* No option of VISIBLE / INVISIBLE */

index_type:

USING {BTREE | HASH}

If you are not looking to upgrade to latest version of MySQL; you can disable this feature of auto-generating with VISIBLE / INVISIBLE index:

In MySQL Workbench:

Go to:

Edit > Preferences > Modeling > MySQL.

Then, set the "Default Target MySQL Version" to 5.7

Check the screenshot below:

raIxn.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值