- 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 are to disable keys, load the data and renalbe the keys:
mysql> ALTER TABLE test.load_data DISABLE KEYS;-- load datamysql> 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
Faster ALTER TABLE ADD column