Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the collation of an existing MySQL database?

How to change the collation of an existing MySQL database?

This is a Drupal 8 site

Currently my database is with collation utf8_general_ci

Is it possible to convert an existing database with collation utf8mb4_unicode_ci?

Is there a risk of damaging the database?

enter image description here

EDIT

Finally the tables are in the format utf8_general_ci

Why is it written in the "Operations" tab utf8_general_ci?

What is the difference between utf8mb4_general_ci and utf8mb4_unicode_ci?

Which "Collation" is currently recommended ?

enter image description here

like image 213
mathieulbt Avatar asked Sep 13 '25 19:09

mathieulbt


1 Answers

You can use the ALTER DATABASE query:

ALTER DATABASE databasename COLLATE utf8mb4_unicode_ci;

This just changes the default collation of the database, which is used when creating new tables, it doesn't modify any existing tables. However, the documentation mentions this caveat regarding stored routines:

If you change the default character set or collation for a database, stored routines that use the database defaults must be dropped and recreated so that they use the new defaults. (In a stored routine, variables with character data types use the database defaults if the character set or collation are not specified explicitly.

like image 128
Barmar Avatar answered Sep 16 '25 08:09

Barmar