I need to change the character set on two MySQL tables to UTF8. Initially I came up with the following query but I wanted to know if this is a safe way to change the character set on (live) tables which have foreign keys. In my dev environment I just used the "FOREIGN_KEY_CHECKS = 0" without the lock but i wasn't so concerned about integrity at the time, with the live system I am.
LOCK TABLES
tags WRITE,
tags_lost WRITE;
SET FOREIGN_KEY_CHECKS = 0;
ALTER TABLE myDB.exampleTable CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE myDB.exampleTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE myDB.exampleTable CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE myDB.exampleTable CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
SET FOREIGN_KEY_CHECKS = 1;
UNLOCK TABLES;
The other option is to lock the tables, drop the foreign key, alter the char set, and then recreate the key but I was just hoping this shortcut would work just as well.