GCP Cloud SQL迁移AWS RDS MySQL时重建索引失败求助
数据库迁移索引创建报错排查请求
我创建了从AWS RDS MySQL到GCP Cloud SQL实例的持续数据库迁移任务,前期一切正常,但8小时后发现新数据库大小变为0,迁移日志中出现如下错误:
错误信息
ERROR: While recreating indexes for table crm.organizations: MySQL Error 1062 (23000): Duplicate entry 'NULL' for key 'organizations.idx_organizations_url'
完整日志条目
DUMP_STAGE(RETRY): Attempt 1/2: import failed: loadDump stderr: ERROR: While recreating indexes for table crm.organizations: MySQL Error 1062 (23000): Duplicate entry 'NULL' for key 'organizations.idx_organizations_url': ALTER TABLE crm.organizations ADD FULLTEXT KEY idx_organizations_organizationName_city (organizationName,city),ADD KEY idx_organizations_Company_Id (Company_Id),ADD KEY idx_organizations_state (state),ADD KEY idx_organizations_insertDate (insertDate),ADD KEY idx_organizations_updateDate (updateDate),ADD KEY idx_organizations_organizationName (organizationName),ADD KEY idx_organizations_city (city),ADD KEY idx_organizations_postalCode (postalCode),ADD KEY idx_organizations_industry (industry),ADD KEY idx_organizations_specialty (specialty),ADD KEY idx_organizations_userId (userId),ADD KEY idx_organizations_dateLastActivity (dateLastActivity),ADD KEY idx_organizations_organizationType (organizationType),ADD KEY idx_organizations_phone (phone),ADD KEY idx_organizations_url (url) , ERROR: [Worker000]: While recreating indexes for table crm.organizations: Duplicate entry 'NULL' for key 'organizations.idx_organizations_url'
我无法理解为何会针对url索引报重复条目错误,因为表中确实存在多条url为NULL的记录,且该索引并非唯一索引。
表结构
CREATE TABLE `organizations` ( `organizationId` binary(16) NOT NULL, `uuid` varchar(36) GENERATED ALWAYS AS (insert(insert(insert(insert(lower(hex(`organizationId`)),9,0,_utf8mb4'-'),14,0,_utf8mb4'-'),19,0,_utf8mb4'-'),24,0,_utf8mb4'-')) VIRTUAL, `Company_Id` bigint DEFAULT NULL, `organizationName` varchar(255) DEFAULT NULL, `address1` varchar(255) DEFAULT NULL, `address2` varchar(255) DEFAULT NULL, `city` varchar(60) DEFAULT NULL, `state` varchar(60) DEFAULT NULL, `postalCode` varchar(20) DEFAULT NULL, `country` varchar(60) DEFAULT NULL, `latitude` double DEFAULT NULL, `longitude` double DEFAULT NULL, `url` varchar(255) DEFAULT NULL, `phone` varchar(45) DEFAULT NULL, `fax` varchar(45) DEFAULT NULL, `industry` varchar(45) DEFAULT NULL, `specialty` varchar(45) DEFAULT NULL, `notes` longtext, `userId` binary(16) DEFAULT NULL, `userUuid` varchar(36) GENERATED ALWAYS AS (insert(insert(insert(insert(lower(hex(`userId`)),9,0,_utf8mb4'-'),14,0,_utf8mb4'-'),19,0,_utf8mb4'-'),24,0,_utf8mb4'-')) VIRTUAL, `organizationType` varchar(255) DEFAULT NULL COMMENT 'organizationType', `dateLastActivity` datetime DEFAULT NULL, `insertDate` datetime DEFAULT CURRENT_TIMESTAMP, `updateDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`organizationId`), KEY `idx_organizations_Company_Id` (`Company_Id`), KEY `idx_organizations_state` (`state`), KEY `idx_organizations_insertDate` (`insertDate`), KEY `idx_organizations_updateDate` (`updateDate`), KEY `idx_organizations_organizationName` (`organizationName`), KEY `idx_organizations_city` (`city`), KEY `idx_organizations_postalCode` (`postalCode`), KEY `idx_organizations_industry` (`industry`), KEY `idx_organizations_specialty` (`specialty`), KEY `idx_organizations_userId` (`userId`), KEY `idx_organizations_dateLastActivity` (`dateLastActivity`), KEY `idx_organizations_organizationType` (`organizationType`), KEY `idx_organizations_phone` (`phone`), KEY `idx_organizations_url` (`url`), FULLTEXT KEY `idx_organizations_organizationName_city` (`organizationName`,`city`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
我尝试通过导出源表并导入到本地无索引数据库,再用单条ALTER TABLE语句添加索引的方式复现问题,但未成功。
环境信息:AWS RDS MySQL版本为8.0.34,Cloud SQL MySQL版本为8.0.31,我认为这并非报错原因。
恳请提供排查思路。
内容的提问来源于stack exchange,提问作者Ian Herbert
相关产品推荐
相关产品推荐

