当前位置:网站首页>使用 percona 工具给 MySQL 表加字段中断后该如何操作
使用 percona 工具给 MySQL 表加字段中断后该如何操作
2022-07-02 12:13:00 【六位元素】
目录
需求
现在有一个MySQL数据库,库中有很多千万级的大表,现在需要给一个几千万级别数据量的大表加字段
方案
由于表数据量太大,通过MySQL客户端命令行直接添加字段是不可取的,因为:直接修改表结构会锁表,由于数据量巨大,执行会非常的慢,并且会影响表的读写。现在绝大多数业务系统,都需要保证7*24小时无间断的提供服务,大表直接修改会导致长时间的表被锁,造成业务中断,影响业务,这种情况肯定是不能接受的。
所以我们需要找一个可行的替代方案,有了,我们使用percona的工具pt-online-change-schema来加字段,这个工具可以在几乎不影响性能的前提下完成表结构的修改。
问题
使用pt-online-change-schema加字段的过程由于连接中断,加字段未能成功,我们重新使用该工具加字段结果报错了,报错信息如下:

这个报错是提示触发器已经存在。
分析
我们知道使用pt-online-change-schema工具来给MySQL的表加字段会创建三个触发器(insert、update、delete),所以我们需要删除这三个触发器后再使用工具给表添加字段。
解决方案
1.查询触发器
select * from information_schema.triggers;
2.删除触发器
找到对应的TRIGGER_SCHEMA和TRIGGER_NAME,比如
drop trigger test.pt_osc_test_t_tab1_ins;
drop trigger test.pt_osc_test_t_tab1_upd;
drop trigger test.pt_osc_test_t_tab1_del;3.重新使用pt-online-change-schema工具执行加字段即可。
边栏推荐
- 【LeetCode】344-反转字符串
- There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
- 【网络安全】网络资产收集
- 自定义异常
- 终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
- 02.面向容器化后,必须面对golang
- 6095. 强密码检验器 II
- [leetcode] 1140 stone game II
- 树-二叉搜索树
- SQL transaction
猜你喜欢

How to avoid 7 common problems in mobile and network availability testing

19_ Redis_ Manually configure the host after downtime

Pytorch 保存tensor到.mat文件
![[experience cloud] how to get the metadata of experience cloud in vscode](/img/45/012c2265402ba1b44f4497f468bc61.png)
[experience cloud] how to get the metadata of experience cloud in vscode

语义分割学习笔记(一)

03.golang初步使用

LeetCode刷题——两整数之和#371#Medium

Leetcode skimming -- count the number of numbers with different numbers 357 medium

Party History Documentary theme public welfare digital cultural and creative products officially launched

How to find a sense of career direction
随机推荐
【LeetCode】1020-飞地的数量
folium,确诊和密接轨迹上图
How to avoid 7 common problems in mobile and network availability testing
Summary of the first three passes of sqli Labs
There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
Deux séquences ergodiques connues pour construire des arbres binaires
【LeetCode】695-岛屿的最大面积
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
Loss function and positive and negative sample allocation: Yolo series
【LeetCode】283-移动零
Folium, diagnosis and close contact trajectory above
损失函数与正负样本分配:YOLO系列
6.12 critical moment of Unified Process Platform
[leetcode] 695 - maximum area of the island
Bing.com网站
Engineer evaluation | rk3568 development board hands-on test
19_ Redis_ Manually configure the host after downtime
语义分割学习笔记(一)
Force deduction solution summarizes the lucky numbers in 1380 matrix
[network security] network asset collection