This is one of our last installments of MYSQL tips, and we have gotten some good feedback from this series. Database hosting is one of the most important aspects of any complex hosted solution, being able to troubleshoot it correctly can save webmasters much time, and angst!
In MySQL, ALTER TABLE statement allows you to modify an existing table in a number of ways, including adding, deleting, or modifying columns or constraints.Â However, it is common to receive a duplicate-key error during alter table.Â This is caused one of two ways:Â either the new character sets map two keys to the same value, or the table is corrupted.Â Either way, run REPAIR TABLE on the table in question.
ALTER TABLE works in the following way:
Create a new table named
A-xxx with the requested structural changes.
Copy all rows from the original table to
Rename the original table to
A-xxx to your original table name.
Because of this, you may also encounter the following Error Code:
Error on rename of ‘./database/name.frm’ to ‘./database/B-xxx.frm’ (Errcode: 17)
This happens when MySQL crashes during an earlier ALTER TABLE operation, and as a result, there is an old table named A-xxx or B-xxx in the directory.Â This is an easy fix:Â simply go to the MySQL data directory and delete all files that have names beginning with A- or B-, as they were just placeholders from the aborted ALTER TABLE operation (or, you may want to move them elsewhere instead of deleting them).Â The default location of the data directory is /var/mysql.
More information is available at: http://dev.mysql.com/doc/refman/5.5/en/alter-table-problems.html.
Happy hosting! And if you have any further questions or comments related to this, fell free to drop us a comment.
The SingleHop Team.