mysqldatabasecollationutf8mb4

Collation change utf8mb4_unicode_ci to utf8mb4_general_ci


For my databases, I used utf8mb4_unicode_ci with utf8mb4 character set as a default. This was a mistake and the folks who are using the databases I created are complaining about the collation. I need to convert it to utf8mb4_general_ci. Am I able to get away with just changing the DB using an alter statement such as:

ALTER DATABASE `#{database}` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Or, will I need to change each individual table and deal with columns even though the charset is the same between the two collations? I can't seem to find definitive answers on this... I'm using MySQL 5.7.2x .


Solution

  • utf8mb4_unicode_520_ci is better than either of the collations you mentioned.

    Why are they complaining? Perhaps JOINs are failing to use indexes. I would argue with them that the old tables should be changed.

    ALTER DATABASE only sets up defaults for future tables. It will not do what you need.

    ALTER TABLE ... CONVERT TO ... for each table is needed. See http://mysql.rjweb.org/doc.php/limits#767_limit_in_innodb_indexes for a similar ALTER. It provides a way to automatically generate all the ALTERs.