Support unicode complet pour MySQL

De MoodleDocs
Révision datée du 10 mars 2017 à 15:35 par Séverin Terrier (discussion | contributions) (Création de la page)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Aller à :navigation, rechercher

Modèle:Environnement

UTF-8

UTF-8 is a character encoding that most websites use. It encodes each of the 1,112,064 valid code points. To store all of this information, four bytes is required. The most popular values are in the three byte region. MySQL by default only uses a three byte encoding and so values in the four byte range can not be stored. Any record that contains a four byte character will not be saved.

MySQL does support full UTF-8 support. It requires certain settings to be configured. From Moodle 3.3 the default will be to use full UTF-8 for MySQL and MariaDB. Existing databases will still run with partial support, but it is recommended to move over to full support.

Moodle comes with a Command Line Interface (CLI) script for converting to full UTF-8 for MySQL (and MariaDB). Before Moodle 3.3 this conversion tool would only change the collation to some variant of 'utf8_bin'. 'utf8_unicode_ci' was the recommended collation. We now recommend 'utf8mb4_unicode_ci'. 'utf8mb4_unicode_ci' supports 4 byte characters (utf8_unicode_ci only supports 3 byte characters) so four byte characters such as Asian characters and emoji should now be fully supported.

This script will attempt to change the database collation, character set, and default table settings.

En résumé :

  • Les installations neuves de Moodle 3.1.5 et 3.2.2 et ultérieures utiliseront utf8mb4 par défaut.
  • Les sites mis à jour vers Moodle 3.1.5 ou 3.2.2 peuvent utiliser le script pour mettre à jour vers utf8mb4.
  • Dans Moodle 3.3, si la base de données n'est pas configurée pour le support UTF-8 complet, un avertissement sera affiché et encouragera à passer à utf8mb4, mais vous pourrez continuer à utiliser utf8 comme avant.

Format de fichier

To allow for large indexes on columns that are a varchar, a combination of settings needs to be set. The file format for the system needs to be using "Barracuda". This allows for the row format to be set to "Compressed" or "Dynamic". To enable this setting see the upgrade steps listed below.

Fichier par table

To enable this setting see the upgrade steps listed below.

Large prefix

This in conjunction with the row format being either "Compressed" or "Dynamic" allows for large varchar indexes above 191 characters. To enable this setting see the upgrade steps listed below.

Étapes de mise à jour

Important : effectuez une sauvegarde complète (de votre base de données) avant d'effectuer des changements ou de lancer le script !

  • Change configuration settings for MySQL (exactly the same for MariaDB). This step is optional. You can run the script and it will try and make these changes itself. If errors occur then try manually changing these settings as listed below.
    • On Linux based systems you will want to alter my.cnf. This may be located in '/etc/mysql/'.
    • Make the following alterations to my.cnf:

[client] default-character-set = utf8mb4

[mysqld] innodb_file_format = Barracuda innodb_file_per_table = 1 innodb_large_prefix

character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci

[mysql] default-character-set = utf8mb4

  • Redémarrez votre serveur MySQL
  • Lancez le script en ligne de commande pour convertir au nouveau codage de caractère et interclassement (nécessite Moodle 3.1.5, 3.2.2 ou plus récent) : php admin/cli/mysql_collation.php --collation=utf8mb4_unicode_ci

La mise à jour est maintenant terminée.