运行 MySQL CREATE TABLE 语句时出现语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9620439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax error when running a MySQL CREATE TABLE statement
提问by user180857
CREATE TABLE users (
user_id INT(8) NOT NULL AUTO_INCREMENT,
user_name VARCHAR(30) NOT NULL,
user_pass VARCHAR(255) NOT NULL,
user_email VARCHAR(255) NOT NULL,
user_date DATETIME NOT NULL,
user_level INT(8) NOT NULL,
UNIQUE INDEX user_name_unique (user_name),
PRIMARY KEY (user_id)
) TYPE=INNODB;
When running this query on the SQL server, I am getting the following error:
在 SQL 服务器上运行此查询时,出现以下错误:
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 'TYPE=INNODB' at line 10
Any help on why this is coming up?
关于为什么会出现这种情况的任何帮助?
回答by hsz
Instead of
代替
TYPE=INNODB
set
放
Engine=InnoDB
回答by dotoree
Use ENGINE=InnoDB;
用 ENGINE=InnoDB;
http://dev.mysql.com/doc/refman/5.0/en/using-innodb-tables.html
http://dev.mysql.com/doc/refman/5.0/en/using-innodb-tables.html
回答by user1252306
Try the following query:
尝试以下查询:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(8) NOT NULL AUTO_INCREMENT,
`user_name` varchar(30) NOT NULL,
`user_pass` varchar(255) NOT NULL,
`user_email` varchar(255) NOT NULL,
`user_date` datetime NOT NULL,
`user_level` int(8) NOT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `user_name_unique` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
回答by Jonathan Leffler
The manual for CREATE TABLEdoesn't include TYPE; it seems to use:
CREATE TABLE的手册不包括 TYPE;它似乎使用:
ENGINE = INNODB;
And that is the default engine, so you don't really need to specify it.
这是默认引擎,因此您实际上不需要指定它。