Mysql – How to convert thesql latin1 to utf8

character encodingiso-8859-1MySQLutf-8

I inherited a web system that I need to develop further.
The system seems to be created by someone who read two chapters of a PHP tutorial and thought he could code…

So… the webpage itself is in UTF8 and displays and inputs everything in it. The database tables have been created with UTF8 character set. But, in the config, there is "SET NAMES LATIN1". In other words, UTF8 encoded strings are populated into the database with forced latin1 coding.

Is there a way to convert this mess to actually store in utf8 and get rid of latin1?

I tried this, but since the database table is set to utf8, this does not work. Also tried this one without success.

I maybe able to do this by reading all tables in PHP with latin1 encoding then write them back to a new database in utf8, but I want to avoid it if possible.

Best Answer

I managed to solve it by running updates on text fields like this:

UPDATE table SET title = CONVERT(CONVERT(CONVERT(title USING latin1) USING binary) USING UTF8)