04. 集群与运维
线上运维
本节主要讨论
线上DDL 导致的数据丢失
ALTER TABLE `user`
ADD COLUMN `user_account_id` bigint NOT NULL DEFAULT 0 COMMENT '用户账户ID 全局',
ADD COLUMN `state_code` int NOT NULL DEFAULT 86 COMMENT '国家地区编码',
ADD UNIQUE KEY `uk_crew_mobile` (`crew_id`,`state_code`,`user_mobile`,`deletion_flag`),
ADD UNIQUE KEY `uk_user_account_id` (`crew_id`,`user_account_id`,`deletion_flag`),
ADD KEY `idx_user_account_id` (`user_account_id`);
执行结果发现现有数据库中违反规则的数据都被删除了。在
#191025 15:00:40 server id 199514850 end_log_pos 290 Query thread_id=2513873 exec_time=1 error_code=0
SET TIMESTAMP=1571986840/*!*/;
/* query from idb-toolkit */ /* rename-8883761-2513873 */RENAME TABLE `crew`.`user` to `crew`.`tp_8883761_del_user`, `crew`.`tp_8883761_ogt_user` to `crew`.`user`
早在
- 创建临时表
create table tp_xxxx_ogt_user - 临时表执行结构变更
alter table xxx add xxx - 把原表中数据导入到临时表
- 变更表名
rename table user to del_user, tp_xxxx_ogt_user to user - 删除原表
可以猜到在执行步骤
然而原生的
问题就出在判断
根本原因是原本