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(Personidint(11) NOT NULL AUTO_INCREMENT,LastNamevarchar(255) NOT NULL,FirstNamevarchar(255) DEFAULT NULL,Ageint(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]