MySQL CREATE TABLE 中的 1064 错误... TYPE=MYISAM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12428755/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:51:17  来源:igfitidea点击:

1064 error in CREATE TABLE ... TYPE=MYISAM

mysqlsyntax

提问by Nicholas Mc Lovinz Rothapfel

Here is my error(if you need any more info just ask)- Error SQL query:

这是我的错误(如果您需要更多信息,请询问)-错误 SQL 查询:

CREATE TABLE dave_bannedwords(

id INT( 11 ) NOT NULL AUTO_INCREMENT ,
word VARCHAR( 60 ) NOT NULL DEFAULT  '',
PRIMARY KEY ( id ) ,
KEY id( id )
) TYPE = MYISAM ;

MySQL said:

MySQL 说:

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=MyISAM' at line 6

1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 6 行的“TYPE=MyISAM”附近使用的正确语法

回答by eggyal

As documented under CREATE TABLESyntax:

CREATE TABLE语法下所述:

Note
The older TYPEoption was synonymous with ENGINE. TYPEwas deprecated in MySQL 4.0 and removed in MySQL 5.5. When upgrading to MySQL 5.5 or later, you must convert existing applications that rely on TYPEto use ENGINEinstead.

注意
较旧的TYPE选项与ENGINE. TYPE在 MySQL 4.0 中被弃用并在 MySQL 5.5 中删除。升级到 MySQL 5.5 或更高版本时,您必须将依赖的现有应用程序转换TYPE为使用ENGINE

Therefore, you want:

因此,您想要:

CREATE TABLE dave_bannedwords(
  id   INT(11)     NOT NULL AUTO_INCREMENT,
  word VARCHAR(60) NOT NULL DEFAULT '',
  PRIMARY KEY (id),
  KEY id(id) -- this is superfluous in the presence of your PK, ergo unnecessary
) ENGINE = MyISAM ;

回答by jwatkins

A complementary note about CREATE TABLE .. TYPE=""syntax in SQL dump files

关于CREATE TABLE .. TYPE=""SQL 转储文件中的语法的补充说明

TLDR: If you still get CREATE TABLE ... TYPE="..."statements in SQL dump files generated by third party tools, it most certainly indicates that your server is configured to use a default sqlmodeof MYSQL40or MYSQL323.

TLDR:如果你仍然得到CREATE TABLE ... TYPE="..."由第三方工具生成的SQL转储文件语句,它肯定表明您的服务器配置为使用默认sqlmodeMYSQL40MYSQL323

Long story

很长的故事

As it was said by others, the TYPEargument to CREATE TABLEhas been deprecated for a long time in MySQL. mysqldumpcorrectly uses the ENGINEargument, unless you specifically ask it to generate a backward compatible dump (for example using --compatible=mysql40in versions of mysqldumpup to 5.7).

正如其他人所说,在 MySQL 中, 的TYPE论点CREATE TABLE已被弃用很长时间。mysqldump正确使用该ENGINE参数,除非您特别要求它生成向后兼容的转储(例如--compatible=mysql40mysqldump高达 5.7 的版本中使用)。

However, many external SQL dump tools (for example, those integrated in MySQL clients such as phpmyadmin, Navicat and DBVisualizer, as well as those used by external automated backup services such as iControlWP) are not specifically aware of this change, and instead rely on the SHOW CREATE TABLE ...command to provide table creation statements for each tables (and just to it make it clear: this is actually a good thing). However, the SHOW CREATE TABLEwill actually produce outdated syntax, including the TYPEargument, if the sqlmodevariable is set to MYSQL40or MYSQL323.

但是,很多外部 SQL 转储工具(例如集成在 MySQL 客户端如 phpmyadmin、Navicat 和 DBVisualizer 中的那些,以及由外部自动备份服务如 iControlWP 使用的那些)并没有特别意识到这一变化,而是依赖于SHOW CREATE TABLE ...为每个表提供表创建语句的命令(并明确说明:这实际上是一件好事)。但是,如果变量设置为or SHOW CREATE TABLE,实际上会产生过时的语法,包括TYPE参数。sqlmodeMYSQL40MYSQL323

Therefore, if you still get CREATE TABLE ... TYPE="..."statements in SQL dump files generated by third party tools, it most certainly indicates that your server is configured to use a default sqlmodeof MYSQL40or MYSQL323.

因此,如果你仍然可以CREATE TABLE ... TYPE="..."通过第三方工具生成的SQL转储文件语句,它肯定表明您的服务器配置为使用默认sqlmodeMYSQL40MYSQL323

These sqlmodes basically configure MySQL to retain some backward compatible behaviours, and using them by default was largely recommended a few years ago. It is however highly improbable that you still have any code that wouldn't work correctly without these modes. Anyway, MYSQL40, MYSQL323and several other similar sqlmodes have themselves been deprecated and are not supported in MySQL 8.0 and higher.

这些sqlmodes 基本上配置 MySQL 以保留一些向后兼容的行为,并且在几年前主要推荐默认使用它们。然而,如果没有这些模式,您仍然有任何代码无法正常工作是非常不可能的。反正MYSQL40MYSQL323其他几个类似sqlmode■找自己被弃用,在MySQL 8.0和更高的不支持。

If your server is still configured with these sqlmodes and you are worried that some legacy program might fail if you change these, then one possibility is to set the sqlmodelocally for that program, by executing SET SESSION sql_mode = 'MYSQL40';immediately after connection. Note that this should only be considered as a temporary patch, and will not work in MySQL 8.0 and higher.

如果您的服务器仍然配置了这些sqlmodes 并且您担心如果您更改这些s 并且您担心某些遗留程序可能会失败,那么一种可能性是sqlmode通过SET SESSION sql_mode = 'MYSQL40';在连接后立即执行来为该程序在本地设置。请注意,这仅应视为临时补丁,在 MySQL 8.0 及更高版本中不起作用。

A more future-proof solution that do not involve rewriting your SQL queries would be to determine exactly which compatibility features need to be enable, and to enable only those, on a per-program basis (as described previously). The default sqlmode(that is, in server's configuration) should ideally be left unset (which will use official MySQL defaults for your current version). The full list of sqlmode(as of MySQL 5.7) is described here: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html.

不涉及重写您的 SQL 查询的更面向未来的解决方案是准确确定需要启用哪些兼容性功能,并且仅启用那些,在每个程序的基础上(如前所述)。sqlmode理想情况下,默认值(即在服务器的配置中)应该保持未设置(这将使用当前版本的官方 MySQL 默认值)。sqlmode此处描述了(从 MySQL 5.7 开始)的完整列表:https: //dev.mysql.com/doc/refman/5.7/en/sql-mode.html

回答by sherif khedr

CREATE TABLE `admnih` (
  `id` int(255) NOT NULL auto_increment,
  `asim` varchar(255) NOT NULL default '',
  `brid` varchar(255) NOT NULL default '',
  `rwtbah` int(1) NOT NULL default '0',
  `esmmwkeh` varchar(255) NOT NULL default '',
  `mrwr` varchar(255) NOT NULL default '',
  `tid` int(255) NOT NULL default '0',
  `alksmfialdlil` int(255) NOT NULL default '0',
  `tariktsjil` varchar(255) NOT NULL default '',
  `aimwke` varchar(255) NOT NULL default '',
  `twkie` text NOT NULL,
  `rwtbahkasah` int(255) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

回答by Rich

SELECT Email, COUNT(*)
FROM user_log    
WHILE Email IS NOT NULL    
GROUP BY Email    
HAVING COUNT(*) > 1    
ORDER BY UpdateDate DESC 

MySQL said: Documentation #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=MyISAM' at line 36

MySQL 说:文档 #1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 36 行的“TYPE=MyISAM”附近使用的正确语法



Which correction below:

以下哪个更正:

CREATE TABLE users_online (
  ip varchar(15) NOT NULL default '',
  time int(11) default NULL,
  PRIMARY KEY  (ip),
  UNIQUE KEY id (ip),
  KEY id_2 (ip)
  TYPE=MyISAM;
)
#                           
# Data untuk tabel `users_online`
#

INSERT INTO users_online VALUES ('127.0.0.1', 1158666872);

回答by Ahmed Abdirazak

Try the below query

试试下面的查询

CREATE TABLE card_types (
  card_type_id int(11) NOT NULL auto_increment,
  name varchar(50) NOT NULL default '',
  PRIMARY KEY  (card_type_id),
) ENGINE = MyISAM ;