在大型mysql表中添加新列 [英] Add a new column in a large mysql table
问题描述
在大型mysql表中添加新列的最快方法是什么?
What would be the fastest way to add a new column in a large mysql table ?
Alter table add列创建完整表的副本,然后用新的create表替换旧表.在运行此过程时,原始表是可读的,但所有插入和更新都将停滞.
Alter table add column creates a copy of the full table, and then replaces the old one with the new create table. While this process is running, the original table is readable, but all inserts and updates are stalled.
在大表上,副本可能需要很长时间,是否有减少副本的方法?
On large tables, the copy can take a long time, is there any way to reduce it ?
推荐答案
您一直在做ALTER TABLE.有效处理此问题的最佳方法是使用MASTER-MASTER设置.
You are stuck doing the ALTER TABLE. The best possible way to effectively deal with this, is to use a MASTER-MASTER setup.
您可以先修改MASTER1,然后仅在生产中使用MASTER2.然后切换并执行完全相反的操作.
You can modify MASTER1 first, and just use MASTER2 in production. Then you switch over and do the exact opposite.
这篇关于在大型mysql表中添加新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!