I have three tables in MySQL (innodb) (X, Y and Z). X is a table with more than 10 million rows, and has primary key of Y as foreign key. Similarly, Z is table with more than 30 million rows and has primary key of Y as foreign key.
Now the problem is that primary key of Y is VARCHAR (something like a md5 hash or GUID). I want to move this key to INT (AUTO_INCREMENT). What is a way to achieve this in mysql, without writing a script in any other language?
Additionally, primary key of table Z is also a VARCHAR (md5/GUID). I would like to change that to integer as well. (It's not a foreign key in any table).
(This may or may not be any better than Ritobroto's suggestion.)
Assuming X links to Y. (Adapt as needed for all the FKs.)
Do something like this for each table.
Get the new
ids
linked up (to replace theguids
). For each link:(This will take a long time.
Re-establish the FKs. For each table:
Practice it on a test machine !!