mysqlsqlcharacter-encodingcollationmodx

Database conversion from latin1 to utf8mb4, what about indexes?


I noticed that my MODX database still uses latin1 character set in the database and in its tables. I would like to convert them to utf8mb4 and update collations accordingly.

Not totally sure how I should do this. Is this correct?

Are indexes updated automatically? Is there something else I should be aware of?

A bonus question: what would be the most suitable latest utf8_unicode collation? Western languages should work.


Solution

  • Changing the default character sets of a table or a schema does not change the data in the column itself, it only changes the default to apply the next time you add a table or add a column to a table.

    To convert current data, alter one table at a time:

    ALTER TABLE <name> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
    

    The collation utf8mb4_0900_ai_ci is faster than earlier collations (at least according to the documentation), and it's the most current and accurate. This collation requires MySQL 8.0.

    The most current collation in MySQL 5.7 is utf8_unicode_520_ci.

    A table-conversion like this rebuilds the indexes, so there's nothing else you need to do.