Hi we have a database where 3 to 4 records are read and write every second on this particular table on which a new column is to be added. This table has more than 60000 records.
I need to add a new column to this.
MySQL>ALTER TABLE tablename ADD columnname int(1);
What would be the safest way to get this done. Is it possible to get this new column added without stopping the MYSQL server and without losing new records during the update process as I assume it will take quite a long time?
MySQL documentation (http://dev.mysql.com/doc/refman/5.1/en/alter-table.html) provides the following information:
“In most cases, ALTER TABLE makes a temporary copy of the original table. MySQL waits for other operations that are modifying the table, then proceeds. It incorporates the alteration into the copy, deletes the original table, and renames the new one. While ALTER TABLE is executing, the original table is readable by other sessions. Updates and writes to the table that begin after the ALTER TABLE operation begins are stalled until the new table is ready, then are automatically redirected to the new table without any failed updates. The temporary table is created in the database directory of the new table.”
According the documentation there should not be any data loss. But as always, before performing any changes to a live system, check out the same scenario on a test machine.