How to convert hungarian mysql entries to utf8

244 Views Asked by At

I have understood in principle how to convert an existing database from latin to utf8. I have already been able to do this successfully with the database I have.

The existing data is in Hungarian. The database fields were previously set to latin1_german1_ci. As a result, words were stored in the database in this way:

Mária

but in the frontend correctly shown as:

Mária

If I now convert everything to utf-8, it works as it should for all new data. But the existing data was not converted in the database and is displayed in the frontend exactly as it is in the database:

Mária

Which makes sense to me because it is utf8. But it is not what I want of course. But how do I get all the existing data in the database to be converted to e.g. "Mária" in first place?

1

There are 1 best solutions below

0
On

That's a "Mojibake" problem (á in place of á) See Trouble with UTF-8 characters; what I see is not what I stored

As for "converting", first decide which case you have, then apply the given ALTER(s): http://mysql.rjweb.org/doc.php/charcoll#fixes_for_various_cases

Tentatively the 2-step ALTER may be the correct approach. However, test before applying it to production. Doing the 'wrong' Alter will leave quite a mess.

Please provide SHOW CREATE TABLE and a sample of SELECT HEX(col), col..., plus the query that was used to give the Mojibake. And SHOW VARIABLES LIKE 'char%';`

Note: For Western European languages, either utf8 or utf8mb4 would be sufficient. But you may as well go for utf8mb4.