您的位置:首页 > 其它

faster alter table add column

2016-08-07 09:41 267 查看
Create a new table (using the structure of the current table) with the new column(s) included.

execute a
INSERT INTO new_table SELECT (column1,..columnN) FROM current_table;


rename the current table

rename the new table using the name of the current table.

1.
CREATE TABLE new_table LIKE table;


2.
INSERT INTO new_table SELECT * FROM table;


3&4.
RENAME TABLE table = old_table, table = new_table;



The usual trick for loading MyISAM table efficiently is to disable keys, load the data and renalbe the keys:


mysql> ALTER TABLE test.load_data DISABLE KEYS;
-- load data
mysql> ALTER TABLE test.load_data ENABLE KEYS;


dropped all indexes -- then added the field  and recreate indexes


REF:

http://stackoverflow.com/questions/5677932/optimize-mysql-for-faster-alter-table-add-column

http://dba.stackexchange.com/questions/9746/mysql-fastest-way-to-alter-table-for-innodb

http://dba.stackexchange.com/questions/134269/fastest-way-to-add-new-column-in-mysql
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: