创建表出错--'type=InnoDB'

时间:2021-10-12 01:22:12

目录:

 

版本1

mysql5.7

版本2

  

版本3

  

关键字

语法错误

   

  • 问题现象
    • 创建表使用如下语法:

DROP DATABASE IF EXISTS shirodb ;

CREATE DATABASE shirodb CHARACTER SET UTF8 ;

USE shirodb ;

CREATE TABLE member (

mid                                        VARCHAR(50),

password                        VARCHAR(32),

name                                VARCHAR(20),

locked                                INT,

CONSTRAINT pk_mid PRIMARY KEY (mid)

) type = innodb;

INSERT INTO member(mid,password,name,locked) VALUES ('admin','hello','管理员',0) ;

INSERT INTO member(mid,password,name,locked) VALUES ('mermaid','hello','老李',0) ;

INSERT INTO member(mid,password,name,locked) VALUES ('mldn','java','隔壁老王',0) ;

  • 出现错误如下:
    • check the manual that corresponds to your MySQL server version for the right syntax to use near 'type = innodb' at line 7        0.000 sec
  • 原因分析
    • type=InnoDB在5.0以前是可以使用的,但5.1之后就不行了。
  • 处理步骤
    • 把type=InnoDB改为engine=InnoDB

DROP DATABASE IF EXISTS shirodb ;

CREATE DATABASE shirodb CHARACTER SET UTF8 ;

USE shirodb ;

CREATE TABLE member (

mid                                        VARCHAR(50),

password                        VARCHAR(32),

name                                VARCHAR(20),

locked                                INT,

CONSTRAINT pk_mid PRIMARY KEY (mid)

) engine = innodb;

INSERT INTO member(mid,password,name,locked) VALUES ('admin','hello','管理员',0) ;

INSERT INTO member(mid,password,name,locked) VALUES ('mermaid','hello','老李',0) ;

INSERT INTO member(mid,password,name,locked) VALUES ('mldn','java','隔壁老王',0) ;