We all tried various alternative methods for modifying the table structure, but pt-online-schema-change (pt-osc) is the most convenient and preferred method for performing the alter online. It has more granular control too. But it may lead to data loss if proper precautionary steps are not taken care of.
In this blog, we are going to modify a column to a unique key using pt-osc, below I have shared the table structure.
mysql> show create table test\G * 1. row * Table: test Create Table: CREATE TABLEtest
(Personid
int(11) NOT NULL AUTO_INCREMENT,LastName
varchar(255) NOT NULL,FirstName
varchar(255) DEFAULT NULL,Age
int(11) DEFAULT NULL, PRIMARY KEY (Personid
) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 1 row in set (0.00 sec)
I have inserted the data of 1000 rows using …
[Read more]