问题描述:mysql在删索引时报错ERROR 1075,如下所示:
数据库:mysql 8.0.11
系统:centos 7.9
1、问题重现
create table test_table1
(
id int(11) not null auto_increment,
name char(100) not null,
address char(100),
description char(100),
unique index uniqidx(id),
index multicolidx(name(20),address(30)),
index comidx(description(30))
);
mysql> alter table test_table1 drop index uniqidx;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
2、异常原因
删除唯一建需先删除自增,在删除唯一建,此处唯一建所在列为自增属性.主键也是同样的道理.
3、解决过程
--删除字段自增属性.
mysql> alter table test_table1 change id id int(11) not null;
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table test_table1 G
*************************** 1. row ***************************
Table: test_table1
Create Table: CREATE TABLE `test_table1` (
`id` int(11) NOT NULL,
`name` char(100) NOT NULL,
`address` char(100) DEFAULT NULL,
`description` char(100) DEFAULT NULL,
UNIQUE KEY `uniqidx` (`id`),
KEY `multicolidx` (`name`(20),`address`(30)),
KEY `comidx` (`description`(30))
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
--再次删除唯一索引
mysql> alter table test_table1 drop index uniqidx;
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0
说明:如上所示,索引成功被删除.
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net