You have a choice.
In any case, you must make a backup before doing this.
One possibility is to disable your service offline and do it locally as you tried. If you do, you must disable key checks and restrictions.
ALTER TABLE bigtable DISABLE KEYS; SET FOREIGN_KEY_CHECKS=0; ALTER TABLE (whatever); ALTER TABLE (whatever else); ... SET FOREIGN_KEY_CHECKS=1; ALTER TABLE bigtable ENABLE KEYS;
This will speed up ALTER TABLE. It will restore indexes immediately when you do ENABLE KEYS.
Another possibility is to create a new table with the new schema that you want, then turn off the keys in the new table, and then do as @Bader suggested and insert the contents of the old table.
After creating a new table, you turn on the keys again, and then rename the old table to some name, for example, "old_bigtable", and then rename the new table to "bigtable".
You may be able to save your service online while you fill out a new table. But this may not work well.
The third possibility is to dump a giant table (into a flat file) and then load it into a new table with a new layout. This is much like the second possibility, except that you get a free backup copy of the table. You can do this pretty quickly with SELECT DATA INTO OUTFILE and LOAD DATA INFILE . To do this, you will need access to the server file system.
In all cases, disable and then re-enable restrictions and keys to speed things up.
O. jones
source share