MySQL Workbench and phpMyadmin

后端 未结 2 1515
眼角桃花
眼角桃花 2020-12-22 09:50

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 \'VISIBLE,

相关标签:
2条回答
  • 2020-12-22 10:36

    MySQL Workbench allows you to set the MySQL target version it uses when generating a schema.

    Edit / Preferences / Modeling / MySQL / set the *Default Target MySQL Version" to 5.5.60.

    It will then refrain from using new Version 8 features when it generates SQL for you.

    0 讨论(0)
  • 2020-12-22 10:48

    The problem here is the difference in syntax across different MySQL server versions. It seems that your MySQL workbench version is 8.0 and above. The code which it is auto-generating is applicable for the MySQL server version 8.0.

    You will need to either upgrade your MySQL server version to 8.0 and above. Or, you can remove the VISIBLE keyword from all the places (where Index is being defined), like below:

    INDEX `fk_TeamStatistik_Team_idx` (`Team_id` ASC) VISIBLE, -- <-- remove VISIBLE
    

    to

    INDEX `fk_TeamStatistik_Team_idx` (`Team_id` ASC),
    

    You will need to do the same thing at other parts of your queries as well.

    Additional Details

    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.5 (your Server version). 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'
    
    index_type:
        USING {BTREE | HASH}
    
    0 讨论(0)
提交回复
热议问题