mysql 使用ALTER TABLE用户的DISABLE KEYS语句时出错

vsmadaxz  于 2023-03-11  发布在  Mysql
关注(0)|答案(1)|浏览(720)

我正在MySQL社区服务器上运行以下Mysql语句- 8.0.32-0ubuntu0.22.04.2

CREATE DATABASE IF NOT EXISTS moviedb;
USE moviedb;
CREATE TABLE creditcards (
id varchar(20) DEFAULT NULL,
first_name varchar(50) DEFAULT NULL,
last_name varchar(50) DEFAULT NULL,
expiration date DEFAULT NULL
)
ALTER TABLE creditcards DISABLE KEYS;
INSERT INTO creditcards VALUES ('001', 'Tom', 'Hanks', '0000-00-00');
INSERT INTO creditcards VALUES ('002', 'Sandra', 'Bullock', '0000-00-00');
INSERT INTO creditcards VALUES ('003', 'Alan', 'Rickman', '0000-00-00');
CREATE TABLE stars (
id int(11) NOT NULL,
first_name varchar(50) DEFAULT NULL,
last_name varchar(50) DEFAULT NULL,
dob date DEFAULT NULL,
photo_url varchar(200) DEFAULT NULL,
PRIMARY KEY (id)
)
INSERT INTO stars VALUES (755011, 'Arnold', 'Schwarzeneggar', '1947-07-30', 'http://www.imdb.com/gallery/granitz/2028/Events/2028/ArnoldSchw_Grani_1252920_400.jpg?path=pgallery&path_key=Schwarzenegger,%20Arnold');
INSERT INTO stars VALUES (755017, 'Eddie', 'Murphy', '1961-04-03', 'http://www.imdb.com/gallery/granitz/2487/Events/2487/EddieMurph_Pimen_2724994_400.jpg?path=pgallery&path_key=Murphy,%20Eddie%20(I)');

我知道这里一定是语法问题,或者是其中一条语句可能导致其他语句出现问题。我得到了以下错误:

ERROR 1064 (42000): 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 'ALTER TABLE creditcards DISABLE KEYS' at line 7
ERROR 1146 (42S02): Table 'moviedb.creditcards' doesn't exist
ERROR 1146 (42S02): Table 'moviedb.creditcards' doesn't exist
ERROR 1146 (42S02): Table 'moviedb.creditcards' doesn't exist
ERROR 1064 (42000): 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 'INSERT INTO stars VALUES (755011, 'Arnold', 'Schwarzeneggar', '1947-07-30', 'htt' at line 9
ERROR 1146 (42S02): Table 'moviedb.stars' doesn't exist

看起来问题出在ALTER TABLE creditcards DISABLE KEYS;语句上。但是,我不知道这里的问题是什么。在线文档在这一点上没有帮助。
已尝试sqlfluff lint

0md85ypi

0md85ypi1#

根据MySQL,
DISABLE KEYS语法在MySQL中无效。此语法用于其他数据库,如MariaDB或Oracle的MySQL Cluster,但不在MySQL中使用。
要禁用MySQL中的键,可以使用ALTER TABLE语句和DISABLE KEYS子句。

CREATE DATABASE IF NOT EXISTS moviedb;
USE moviedb;
CREATE TABLE creditcards (
id varchar(20) DEFAULT NULL,
first_name varchar(50) DEFAULT NULL,
last_name varchar(50) DEFAULT NULL,
expiration date DEFAULT NULL
);
**ALTER TABLE creditcards DISABLE KEYS;**
INSERT INTO creditcards VALUES ('001', 'Tom', 'Hanks', '0000-00-00');
INSERT INTO creditcards VALUES ('002', 'Sandra', 'Bullock', '0000-00-00');
INSERT INTO creditcards VALUES ('003', 'Alan', 'Rickman', '0000-00-00');
CREATE TABLE stars (
id int(11) NOT NULL,
first_name varchar(50) DEFAULT NULL,
last_name varchar(50) DEFAULT NULL,
dob date DEFAULT NULL,
photo_url varchar(200) DEFAULT NULL,
PRIMARY KEY (id)
);
INSERT INTO stars VALUES (755011, 'Arnold', 'Schwarzeneggar', '1947-07-30', 'http://www.imdb.com/gallery/granitz/2028/Events/2028/ArnoldSchw_Grani_1252920_400.jpg?path=pgallery&path_key=Schwarzenegger,%20Arnold');
INSERT INTO stars VALUES (755017, 'Eddie', 'Murphy', '1961-04-03', 'http://www.imdb.com/gallery/granitz/2487/Events/2487/EddieMurph_Pimen_2724994_400.jpg?path=pgallery&path_key=Murphy,%20Eddie%20(I)');

希望这对你有帮助。

相关问题