在MySQL中,当我尝试通过此查询更改主键时:
ALTER TABLE `resources` DROP PRIMARY KEY, ADD
PRIMARY KEY (`role_id`, `category_id`, `lang`, `model`, `rule`);
我用MySQL root用户执行此查询,但是发生了以下错误:
#1878 - Temporary file write failure.
我的桌子设计是:
CREATE TABLE `resources` (
`role_id` INT(11) UNSIGNED NOT NULL ,
`category_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 1 ,
`lang` BINARY(2) NOT NULL ,
`model` SMALLINT(5) UNSIGNED NOT NULL ,
`rule` CHAR(4) NOT NULL ,
PRIMARY KEY (`category_id`, `lang`, `model`, `rule`, `role_id`)
)
ENGINE = InnoDB;
该表有大约2000行.
我使用MySQL 5.6
为什么会发生此错误?
我该怎么办?
解决方法:
我遇到了同样的问题,我做了以下事情:
create table resources_with_key like resources;
alter table resources_with_key add primary key(`category_id`, `lang`, `model`, `rule`, `role_id`);
insert into resources_with_key select * from resources;