SQL 查询在 phpMyAdmin 上不起作用,因为我收到错误

2022-01-05 00:00:00 sql mysql phpmyadmin

我已在 phpMyAdmin 上输入此代码作为 SQL 查询.我正在尝试创建一个表(这是从另一个站点复制粘贴的代码)

I have entered this code on phpMyAdmin as an SQL query. I am trying to create a table (this is a copy and pasted code from another site)

   CREATE TABLE `members` (
`id` int(4) NOT NULL auto_increment,
`username` varchar(65) NOT NULL default '',
`password` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;
-- 
-- Dumping data for table `members`
--
INSERT INTO `members` VALUES (1, 'john', '1234');

我收到错误

"#1064 - 您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以在第 6 行的 'TYPE=MyISAM AUTO_INCREMENT=2' 附近使用正确的语法"

"#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 AUTO_INCREMENT=2' at line 6 "

推荐答案

指定存储引擎应该是ENGINE而不是TYPE:

It should be ENGINE not TYPE to specify the storage engine:

CREATE TABLE `members` (
`id` int(4) NOT NULL auto_increment,
`username` varchar(65) NOT NULL default '',
`password` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 ;

参见CREATE TABLE 语法:

table_option:引擎 [=] 引擎名称

table_option: ENGINE [=] engine_name

选项 TYPE 在 MySQL 5.5 中被删除,从 MySQL 4.0 开始弃用:

The option TYPE was removed with MySQL 5.5, deprecated since MySQL 4.0:

较旧的 TYPE 选项是 ENGINE 的同义词.类型已自 MySQL 4.0 起已弃用,但仍支持向后MySQL 5.1 中的兼容性(MySQL 5.1.7 除外).从 MySQL 5.1.8 开始,它会产生警告.它在 MySQL 5.5 中被删除.你不应该使用在任何新应用程序中键入,您应该立即开始将现有应用程序转换为使用 ENGINE.(见MySQL 5.1.8 发行说明.)

The older TYPE option was synonymous with ENGINE. TYPE has been deprecated since MySQL 4.0 but is still supported for backward compatibility in MySQL 5.1 (excepting MySQL 5.1.7). Since MySQL 5.1.8, it produces a warning. It is removed in MySQL 5.5. You should not use TYPE in any new applications, and you should immediately begin conversion of existing applications to use ENGINE instead. (See the Release Notes for MySQL 5.1.8.)

来源:创建表,MySQL 5.1

相关文章