After upgrading MySQL 5.7 -> 8.0, we realized we needed to convert all tables from latin1
to utf8
. After a long googling, I found that the best solution for that is to convert the columns with text datatypes first to VARBINARY (or BLOB for texts) and then back to VARCHAR (text) with the correct CHARACTER SET.
Running the command:
ALTER TABLE [table] MODIFY COLUMN [column] VARBINARY([size]);
runs fine and the column got changed to the VARBINARY
type.
But the conversion back:
ALTER TABLE [table] MODIFY COLUMN [column] VARCHAR([size]) CHARACTER SET utf8mb4;
returns an error:
Incorrect string value: '\xF3nica' for column '[column]' at row [index]
The value is random across tables and columns, but every time it happens if the field has some non-ANSI character (like accents, non-English letters, etc.). This particular error happens with the first name column containing Mónica
(xF3 = ó). Why it incorrect for UTF8mb4?
I'm also frustrated about this error because when we used to run MySQL 5.7 with the default character set latin1,
we had no errors with non-Latin characters. Everything was working fine. The problem started after the MySQL version upgrade.