Changing a MySQL database from latin1 to utf8

17
Jun
0

Yesterday I found a solution on the german site administrator.de to quickly change a whole MySQL database from latin1 (latin1_general_ci) to utf8 (utf8_general_ci).

ALTER DATABASE `database` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `table1` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `table2` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `table3` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

After running the above SQL script, the whole database including all (text) fields are converted to utf8.

Filed under: MySQL