Converting iso-8859-1 data to UTF-8 in UTF8 and Latin1 tables
Setting a column to latin1
and others to utf8
is perfectly fine in MySQL. There's no problem to be solved here as such. This charset parameter just influences how the data is stored internally. Which of course also means that you cannot store, for example, "漢字" in a latin1
column. But assuming you're just storing "Latin-1 characters" in there, that's fine.
MySQL has something commonly called the connection encoding. It tells MySQL what encoding text is in that you send to it from PHP (or elsewhere), and what encoding you'd like back when retrieving data from MySQL. The column charset, the "input connection encoding" and "output connection encoding" can all be different things, MySQL will convert encodings on the fly accordingly as needed.
So, assuming you've used the correct connection encodings so far and data is stored properly in your database and you've not tried to store non-Latin-1 characters in Latin-1 columns, all you need to do to update your column charsets to UTF-8 is:
ALTER TABLE table MODIFY column TEXT [...] CHARACTER SET utf8;
You can try mysqldump to convert from ISO-8859-1 to utf-8:
mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sqlchgrep latin1 utf8 dump.sql (or when you prefer sed -i "" 's/latin1/utf8/g' dump.sql) mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"mysql --user=username --password=password --default-character-set=utf8 dbname < dump.sql
You may get rid of the "glyph" characters (�) by applying utf8_encode to the string before displaying it in your page.